Asp. net-finding nested controls in a repeater control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.