c# - RowIndex out of range -


i'm having trouble code. i'm trying show different picture each case. code seems flawed, i'm pretty new c# , asp.net lost pretty easily. here's portion of code crashes:

    protected void onrowdatabound(object sender, gridviewroweventargs e)     {         gridviewrow row = gridview1.rows[e.rowindex];         string class = (e.row.findcontrol("txtclass") textbox).text;         htmlcontrol htmctrl = e.row.findcontrol("imgid") htmlcontrol;         switch (class)         {             case "a1":                 {                     string logo = @"c:\users\rudra\documents\visual studio 2010\projects\mvcapplication1\mvcapplication1\images\box_blue.png";                     htmctrl.attributes.add("src", logo);                     break;                 }             case "a2":                 {                     string logo = @"c:\users\rudra\documents\visual studio 2010\projects\mvcapplication1\mvcapplication1\images\box_green.png";                     htmctrl.attributes.add("src", logo);                     break;                 }             case "a3":                 {                     string logo = @"c:\users\rudra\documents\visual studio 2010\projects\mvcapplication1\mvcapplication1\images\box_red.png";                     htmctrl.attributes.add("src", logo);                     break;                 }             default:                 {                     string logo = @"c:\users\rudra\documents\visual studio 2010\projects\mvcapplication1\mvcapplication1\images\not-found.png";                     htmctrl.attributes.add("src", logo);                     break;                 }         }     } 

the crash happens on first line gridviewrow row = gridview1.rows[e.rowindex];. rowindex not recognised (doesn't show on intellisense). if can see went wrong, why crashes , how fix i'd eternally grateful.

you need not convert

gridviewrow row = gridview1.rows[e.rowindex]; 

instead can directly use

gridviewrow row = e.row; 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -