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