: Check box for Asp.net to select all Groups

Source: Internet
Author: User

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. html in aspxCodeEnter the following functions in Head
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;


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>
<Input id = "tow.shi2_1" type = "checkbox" name = "to1: shi2: 1"/>
<Label for = "tow.shi2_1"> 5 </label>
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.



Related Article

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.