Using foreach to traverse the page control and the use of the trinocular operator

Source: Internet
Author: User

1. Using foreach to traverse the page control and the use of the trinocular operator

Use Div to put a set of checkboxes together for traversing

<body> <form id="Form1"runat="Server"> <div> <asp:checkbox id="cb_1"runat="Server"autopostback="true"text="I was automatic."oncheckedchanged="cb_1_checkedchanged"/> <asp:textbox id="tb_1"runat="Server"></asp:TextBox> <br/> <br/> <br/> <div id="chklist"runat="Server"> <asp:checkbox id="cb_2"runat="Server"text="Reading"/> <asp:checkbox id="Cb_3"runat="Server"text="Listen to the song"/> <asp:checkbox id="Cb_4"runat="Server"text="Travel"/> <asp:checkbox id="cb_5"runat="Server"text="Dancing"/> <br/> <asp:button id="Button1"runat="Server"text="Button"onclick="Button1_Click"/><br/> <asp:textbox id="tb_2"runat="Server"Textmode="MultiLine"Width="300px"height="300px"></asp:TextBox> </div> </div> </form></body>

 protected voidPage_Load (Objectsender, EventArgs e) {        }        protected voidCb_1_checkedchanged (Objectsender, EventArgs e) {Tb_1.text= (cb_1.checked)?"is selected":"not be selected";//The three-mesh operator determines whether it is used        }        protected voidButton1_Click (Objectsender, EventArgs e) {Tb_2.text=" ";//Clear before DisplayCheckBox _chk; foreach(Control ctlinchChklist. Controls)//chklist parent class for Div Control for checkbox, etc.            {                if(CTL isCheckBox)//exclude other controls and make sure it is a checkbox{_chk= (CheckBox) CTL;//Type Conversions                   if(_chk. Checked = =true) {Tb_2.text+ = _chk. Text +","; }                }            }        }

Using foreach to traverse the page control and the use of the trinocular operator

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.