Repeater获取HeaderTemplate和FooterTemplate模板中的控件

来源:互联网 发布:知伯地黄丸 编辑:程序博客网 时间:2024/05/18 08:52

Label lblShowName = this.rpTotalScoreByGroup.Controls[0].FindControl("lblShowName") as Label;

 

在Repeater的ItemTemplate模板中的控件,可以用Items属性来遍历行并用FindControl进行寻找:

rpt.items[i].FindControl("hid_id").

 

如果在HeaderTemplate和FooterTemplate模板中的控件就无能为力了,此时我们只能用Controls属性来解决问题

 

HeaderTemplate和FooterTemplate是Repeater的Controls中的第一个对象和最后一个对象,先获取对象再用FindControl来寻找就Ok了,如下:

rpt.Controls[0].FindControl("header_hidId")

 

 

rpt.Controls[rpt.Controls.Count-1].FindControl("FooterId")