c# - Error "Index was out of range" in ASP.Net application -


i making application asp.net / c # have gridview checkbox in each row.

the problem of them selecting , clicking "save" following error occurs:

index out of range. must non-negative , less size of collection. \ r \ nparameter name: index.

and error seems occurring in last row of gridview. follow snippet of code , properties window gridview:

c#

protected void btnokvulsproj_click(object sender, eventargs e)     {              //variables          (int cont = 0; cont < grdlistavulsproj.rows.count; cont++)         {             idvul = convert.toint32((grdlistavulsproj.rows[cont].cells[0]).text);              string strqueryinsert = ("insert database");              if (((checkbox)grdlistavulsproj.rows[idvul].findcontrol("chkselecionaitem")).checked)  <<< error occurs              {                 conexao.inserir(strqueryinsert); //method performs insertion             }         };              //other instructions      } 



gridview properties's

http://i56.tinypic.com/33f3hqf.jpg

note: gridview aims register on database rows selected.

note2: searched extensively web solution, presented, none of them solved problem.

thank you!

[ ]'s

your line should be:

if (((checkbox)grdlistavulsproj.rows[cont].findcontrol("chkselecionaitem")).checked)  <<< error occurs   

Comments