How do I find controls in headertemplate and footertemplate templates of repeater?

Source: Internet
Author: User

In the itemtemplate template of repeater, we can use the items attribute to traverse rows and use findcontrol for search,

As shown below: traverse under the item command event of 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 attribute to solve the problem. Assume that the page contains the following Repeater control:

Program code <asp: repeater id = "repeater1" runat = "server">
<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>

BottomCodeFor example, find label1 and label3:

Program code // search for label1 in headertemplate. The default value is 0th string S = (Label) repeater1.controls [ 0 ]. Findcontrol ("label1"). Text; // search for label2 in footertemplate. The default value is the last string S = (Label) repeater1.controls [ Repeater1.controls. Count-1 ]. Findcontrol ("label2"). text;

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.