在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
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
但是,如果在HeaderTemplate和FooterTemplate模板中的控件就无能为力了,此时我们只能用Controls属性来解决问题。假设页面中有如下一个Repeater控件: 程序代码
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
下边代码示例寻找Label1和Label2:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)