Frog frog recommendation: check box for Asp.net to select all Groups
1. Declare controls. A checkbox at the top of the page is called cb5, and a checkboxlist is called shi2:
Protected system. Web. UI. webcontrols. checkbox cb5;
Protected system. Web. UI. webcontrols. checkboxlist shi2;
2. type the following function in the header of the HTML code of aspx:
<SCRIPT>
Function chkchk (chkid, spanid ){
VaR o = Document. getelementbyid (chkid );
VaR OBJ = Document. getelementbyid (spanid );
OBJ = obj. Children;
For (I = 0; I <obj. length; I ++)
{
E = OBJ [I];
If (E. type = "checkbox "){
OBJ [I]. Checked = O. checked;
}
}
}
</SCRIPT>
3. Add custom attributes in the background Encoding
Private void page_load (Object sender, system. eventargs E)
{
Cb5.attributes. Add ("onclick", "chkchk ('" + cb5.clientid + "', '" + shi2.clientid + "');");
}
4. Let's observe some automatically generated HTML code and we will understand it.
<Input id = "tow.cb5" type = "checkbox" name = "to1: cb5" onclick = "chkchk ('to1 _ cb5', 'to1 _ shi2');"/>
<Label for = "tow.cb5"> Municipal Bar Association </label>
<Span id = "tow.shi2">
<Input id = "tow.shi2_0" type = "checkbox" name = "to1: shi2: 0"/>
<Label for = "tow.shi2_0"> admin </label>
<Br>
<Input id = "tow.shi2_1" type = "checkbox" name = "to1: shi2: 1"/>
<Label for = "tow.shi2_1"> 5 </label>
</Span>
5. note that I put all the controls in a to1 usercontrol, so the generated control ID is preceded by a "to1 _", which is one afternoon, asp.net does not work very well in programming some clients. If no script is written, you can only use server events for association selection. Therefore, you need to click the check box to return the form, this is not worthwhile in terms of performance, and it is only possible to make a decision. the main knowledge in this article is the JavaScript document object and the nested model of controls, as well as adding some client behavior attributes to the server controls.
Finally, I would like to thank Henman's technical support from the donet technical exchange group.