asp.net - how to access templatefield from code behind -


the reason why looking update dynamic because using objectdatasource , objectdatasource have collection of object , within object have object wanted access example:

+student   ......   ......   ......   -courses     .........     .........     name 

update end

how bind templatefield code-behind?

<asp:gridview id="gridview1" runat="server"> <columns>  <asp:templatefield headertext="name" sortexpression="name">                     <itemtemplate>                                            </itemtemplate>                  </asp:templatefield>  </columns> </asp:gridview> 

first of define key field in gridview control, add net attribute gridview markup: datakeynames="studentid".

you can use both event handler gridview: rowdatabound or rowcreated. add 1 of event handler , find there control placed in itemtemplate. here, instance:

void productsgridview_rowcreated(object sender, gridviewroweventargs e)   {      if(e.row.rowtype == datacontrolrowtype.datarow)     {       // retrieve linkbutton control first column.       label somelabel = (label)e.row.findcontrol("somelabel");       if (somelabel != null)       {           // student index           int studentid = (int)gridview.datakeys[e.row.rowindex].values[0];           // set label text           // define here courses regarding current student id                         somelabel.text = //        }     }    } 

this example gotten msdn


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -