gridview里HeaderTemplate的LinkButton1后台找不到
<asp:GridView ID="GridView1" runat="server" >
<Columns>
<asp:TemplateField ShowHeader="true">
<HeaderTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">AA</asp:LinkButton>
</HeaderTemplate>
</Columns>
</asp:GridView>
上面是前端部分代码,现在GridView1 里 HeaderTemplate 的 LinkButton1,
我在后台文件想写
LinkButton1.Text = 时,提示找不到LinkButton1,
如何解决?
------解决方案--------------------你要先把LinkButton对应的列的里面有个FindControl方法找到“LinkButton1”这个名称,再把它转换成LinkButton控件,这里你才能对这个控件操作
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
Control c = this.GridView1.Rows[this.GridView1.SelectedIndex].FindControl("LinkButton1");
LinkButton lb = (LinkButton)this.GridView1.Rows[this.GridView1.SelectedIndex].FindControl("LinkButton1");
lb.Text = "test";
}
------解决方案--------------------更多参考:
在GridView中使用FindControl .
http://blog.csdn.net/qdzx2008/article/details/4558388