GridView如下:






<asp:TemplateField HeaderText="正确率"> //control[3]







我们现在要在 GridView1_RowDataBound(object sender, GridViewRowEventArgs e)事件中获取
<asp:Label ID="bfb" runat=server>aa</asp:Label>的引用
代码如下:
1 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
2 {
3 if (e.Row.RowType == DataControlRowType.DataRow)
4 {
5 Label bfb = (Label)e.Row.Controls[3].FindControl("bfb");
6
7 }
8
9 }
2 {
3 if (e.Row.RowType == DataControlRowType.DataRow)
4 {
5 Label bfb = (Label)e.Row.Controls[3].FindControl("bfb");
6
7 }
8
9 }
上面的第五行代码 Label bfb = (Label)e.Row.Controls[3].FindControl("bfb");
也可以改为 Label bfb = (Label)e.Row.Controls[3].Controls[1];
因为

包含



三个子控件,所以label 的index为1。