c# - Must be non-negative and less than the size of the collection -


i try submit documents through dropdownlist when admin select approve/reject in gridview once click on submit button action performed code in submit button

  protected void button1_click(object sender, eventargs e)     {         //foreach (gridviewrow row in grdfileapprove.rows)         //{         //    //if row in datarow go ahead , find control         //    if (row.rowtype == datacontrolrowtype.datarow)         //    {         //        dropdownlist dropdownlistcontrol = row.findcontrol("dropdownlist4") dropdownlist;           //    }         //}         string connstr         configurationmanager.connectionstrings["mydms"].connectionstring;         sqlconnection mysqlconnection = new sqlconnection(connstr);         if (mysqlconnection.state == connectionstate.closed)         {             mysqlconnection.open();         }          // sql command object           //sqlcommand mysqlcommand;           dropdownlist drdlist;         foreach (gridviewrow row in grdfileapprove.rows)         {             drdlist = (dropdownlist)         (grdfileapprove.rows[row.rowindex].cells[1].findcontrol("dropdownlist4"));             if (grdfileapprove.datakeys[row.rowindex]["approveid"].tostring() !=        drdlist.selectedvalue)       {          sqlcommand cmd = new sqlcommand("approved", mysqlconnection);     }   }    if (mysqlconnection.state == connectionstate.open)   {       mysqlconnection.close();   }   

it show me error in line

if (grdfileapprove.datakeys[row.rowindex]["approveid"].tostring() !=        drdlist.selectedvalue)  

error

index out of range. must non-negative , less size of collection. parameter name: index

any solution?

look @

grdfileapprove.datakeys[row.rowindex]["approveid"] 

i'd put breakpoint in line , check grdfileapprove.datakeys , see if row.rowindex value , "approveid" valid access datakeys collection.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -