首先我们用RadioButtonList控件,且必须包含OnSelectedIndexChanged事件和AutoPostBack=‘true’属性,
<asp:LinkButton ID="lbtnPaperNameDis_TP" runat="server" Text="全选" onclick=btn1_click></asp:LinkButton> <asp:LinkButton ID="lbtnPaperNameDis_TP1" runat="server" Text="反选" onclick=btn2_click ></asp:LinkButton>
然后在OnSelectedIndexChanged事件里写如下代码:
public void btn1_Click() { if (checkboxlistName.Items[0].Selected == true) { for (int i = 0; i < checkboxlistName.Items.Count; i++) { checkboxlistName.Items[i].Selected = true; } } else { for (int i = 0; i < checkboxlistName.Items.Count; i++) { checkboxlistName.Items[i].Selected = false; } } } puclic void btn2_Click() { for (int i = 0; i < checkboxlistName.Items.Count; i++) { checkboxlistName.Items[i].Selected = !checkboxlistName.Items[i].Selected; } }
ok,完成!