How do I find controls in Repeater's HeaderTemplate and FooterTemplate templates? In Repeater's ItemTemplate template, we can use the Items property to iterate through the rows and look for them with FindControl.
As follows: Under the item command event for repeater:
for (int i=0; i<repeater1. items.count;i++) { checkbox cb= (checkbox) Repeater1. Items[i]. FindControl ("CheckBox1"); if (CB. Checked) { // related data processing} }
However, if the controls in the HeaderTemplate and FooterTemplate templates are powerless, we can only use the Controls property to solve the problem. Suppose you have one of the following repeater controls on the page:
Program Code <HeaderTemplate>
<asp:label id= "Label1" runat= "Server" text= "AAAAAAA" ></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:label id= "Label2" runat= "server" text= ' <%# Eval ("name")%> ' ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:label id= "Label3" runat= "Server" text= "BBBBBBB" ></asp:Label>
</FooterTemplate>
</asp:Repeater>
The following code example looks for Label1 and LABEL3:
As follows: Traversing under the Repeater Item command event
for (int i=0; i<repeater1. items.count;i++) { checkbox cb= (checkbox) Repeater1. Items[i]. FindControl ("CheckBox1"); if (CB. Checked) { // related data processing} }
Asp. net-finding nested controls in a repeater control