Asp.net| Group | check box 1. Declare the control, at the top of the page a checkbox 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 head of the ASPX HTML code
<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 to the background code
private void Page_Load (object sender, System.EventArgs e)
{
Cb5. Attributes.Add ("onclick", "Chkchk" ("+CB5"). Clientid+ "', '" +shi2. Clientid+ "");
}
4. We'll look at some auto-generated HTML code, and we'll see
<input id= "to1_cb5" type= "checkbox" Name= "TO1:CB5" onclick= "Chkchk" (' to1_cb5 ', ' to1_shi2 '); "/>
<label for= "TO1_CB5" > City Bar Association </label>
<span id= "To1_shi2" >
<input id= "to1_shi2_0" type= "checkbox" Name= "to1:shi2:0"/>
<label for= "To1_shi2_0" >admin</label>
<br>
<input id= "to1_shi2_1" type= "checkbox" Name= "To1:shi2:1"/>
<label for= "To1_shi2_1" >5</label>
</span>
5. Note I put all the controls in a to1 UserControl inside, so the generated control ID is preceded by a "to1_", but also an afternoon time, the whole out of a this, the total sense of asp.net to some client-side programming is not very good, if not write script, If you make a linkage selection, you can only use server events, this will be every click check box to return to the form, which is very not worth considering the performance, can only do this. The main knowledge points of this article are JavaScript document objects and the nested model of the controls, plus some client behavior properties for server controls .
Finally, thanks to the technical support of Henman sister of Donet Technology Group