在Repeater的ItemTemplate模板中的控件,我们可以用Items属性来遍历行并用FindControl进行寻找,
如下所示:在Repeater的Item Command事件下下遍历:
1 for(int i=0;i<repeater1.Items.Count;i++) 2 { 3 CheckBox cb=(CheckBox )repeater1.Items.FindControl("CheckBox1"); 4 if(cb.Checked) 5 { //相关数据处理 } 6 } |
但是,如果在HeaderTemplate和FooterTemplate模板中的控件就无能为力了,此时我们只能用Controls属性来解决问题。假设页面中有如下一个Repeater控件。
程序代码如下:
1![]() 2 ![]() 3 ![]() 4 ![]() 5 ![]() 6 ![]() 7 ![]() 8 ![]() 9 ![]() 10 ![]() 11 ![]() 12 ![]() |
下边代码示例寻找Label1和Label3:
1![]() 2 ![]() 3 ![]() 4 ![]() 5 ![]() |