asp.net - How do I change the image on a <asp:buttonField type="Image" /> in code behind? -


i have <asp:gridview > <asp:buttonfield buttontype="image"> 1 of columns.

here's problem: have dynamically change image of buttonfield during gridview_rowdatabound(...) event based on data found in particular gridview row.

the real question is, how access particular buttonfield inside gridview_rowdatabound(...) event can change image in c# code?

i can't use

image imgctrl = (image)args.row.findcontrol("ctrlid"); 

because <asp:buttonfield> won't allow id set (get parser error when try run webpage). , can't use

args.row.cells[0].controls[0]; 

because zeroth index of .controls[0] doesn't exist (i boundry overflow error).

there's got simple, slick, easy way this!

quick example :

    protected void gridview1_rowdatabound(object sender, gridviewroweventargs e)     {         datarowview drv = (datarowview)e.row.dataitem;          if (e.row.rowtype == datacontrolrowtype.datarow)         {             tablecell tablecell = e.row.cells[3]; // column 3 in grid have image button              foreach (var control in tablecell.controls)             {                 if (control.gettype() == typeof(system.web.ui.webcontrols.imagebutton)) ;                 {                     imagebutton ibutton = control imagebutton;                     ibutton.imageurl = "/logo.jpg";                 }             }         }     } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -