The findcontrol () method and the checkbox in Repeater

Source: Internet
Author: User

today, we need to create a checkbox for the repeater, and then we can perform reverse labeling. This is simple, but I have found a good advantage of the findcontrol method.
the frontend binding method is as follows:


BackgroundCodeAs follows:
Foreach (control C in this. repeater1.controls)
{
Checkbox check = (checkbox) C. findcontrol ("ch ");
If (check! = NULL)
{
Check. Checked = true;
}

}

It seems that there is nothing magical to look at, but from the HTML code, you can see the HTML code generated by repeater is as follows:
<Input id = repeater1_ctl00_ch type = checkbox name = repeater1 $ ctl00 $ ch>
<Input id = repeater1_ctl03_ch type = checkbox name = repeater1 $ ctl03 $ ch>
Everyone on Earth knows that when the server ID arrives at the client, it is very likely that Asp.net will automatically rename the control tree generated by Asp.net to prevent multiple duplicate IDs on one page, so why can I use findcontrol ("ch") in the background when sending a response? This is what Asp.net has done for us.

By the way, there are three methods to get the checkbox in repeater:
Foreach (Repeateritem item In   This . Repeater1.items)
  {
Htmlinputcheckbox check = (Htmlinputcheckbox) item. findcontrol ( " Cbdelete1 " );
If (Check ! =   Null )
{
Check. Checked= True;
}
}  

For ( Int I = 0 ; I < This . Repeater1.items. Count; I ++ )
{
Htmlinputcheckbox check = (Htmlinputcheckbox) This . Repeater1.items [I]. findcontrol ( " Cbdelete1 " );
If (Check ! =   Null )
{
Check. Checked= True;
}
}

Foreach (Control C In   This . Repeater1.controls)
{
Htmlinputcheckbox check = (Htmlinputcheckbox) C. findcontrol ( " Cbdelete1 " );
If (Check ! =   Null )
{
Check. Checked= True;
}

}

Yes.

Foreach (control C in this. repeater1.controls)
{
Checkbox check = (checkbox) C. findcontrol ("cbdelete1 ");
Check. Checked =! Check. checked;
}

From http://www.cnblogs.com/FrameWork/archive/2006/11/25/571928.html

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.