When the gridview control is not added to a template, it is easy to get the value of a row or column.
For example:
E. Row. cells [3]. Text // gets the content in the fourth unit of the currently selected row. Here I put this line of code in the onrowdatabound event handler.
However, if templatefield is added to this column, as follows:
<Asp: templatefield headertext = "item name">
<Edititemtemplate>
<Asp: textbox id = "textbox1" runat = "server" text = '<% # BIND ("modelname") %>'
Width = "85px"> </ASP: textbox>
</Edititemtemplate>
<Itemtemplate>
<Asp: Label id = "label1" runat = "server" text = '<% # BIND ("modelname") %>'> </ASP: Label>
</Itemtemplate>
<Itemstyle horizontalalign = "center" width = "95px"/>
</ASP: templatefield>
At this time, if you use the previous method to obtain the value, the null value will be obtained. In this case, you need to use findcontrol to obtain the value according to the following methods:
Label lbl1 = (Label) E. Row. findcontrol ("label1"); // The ID in itemtemplate instead of edititemtemplate
String Ss = lbl1.text;
In this way, the desired value can be obtained correctly.