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