c# - Index was out of range. Must be non-negative and less than the size of the collection. -


i getting error(index out of range. must non-negative , less size of collection. parameter name: index) in gridview_rowupdating event. tried ideas posted here, still getting error.

code behind

protected void gridview1_rowupdating(object sender, gridviewupdateeventargs e) {     label stu_name= ((label)gridview1.rows[e.rowindex].findcontrol("student_name")); } 

check if viewstate enabled gridview1.

if viewstate disabled, asp.net not able update because asp.net handle update or other events needs preserve previous data well.

in case, viewstate==false, gridview1.rows[e.rowindex], fail because gridview1.rows.count 0.

also if doing databind in page_load, make sure databind if !ispostback.

if(!ispostback)  // databind grid .. 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -