设置那个要点的CheckBox的AutoPostBack属性为True?

解决方案 »

  1.   

    use client side javascript, try something like<form runat="server">
    <asp:checkboxList id="clb" runat="Server">
     <asp:ListItem Text="1"/>
     <asp:ListItem Text="2"/>
     <asp:ListItem Text="3"/>
    </asp:checkboxList>
    <asp:CheckBox id="cb" runat="server" Text="Select All"/>
    </form>
    <script language="javascript">
    function selectCheckboxList()
    {
      var inputs = document.all("clb").all.tags("INPUT");
      for (var i=0; i < inputs.length; i++)
    inputs[i].checked = document.all("cb").checked;
    }document.all("cb").onclick=selectCheckboxList;
    </script>
      

  2.   

    if you could do it on the client side, why do you ever want to do it on the server side? but if you insist, try
    <form runat="server">
    <asp:checkboxList id="clb" runat="Server">
     <asp:ListItem Text="1"/>
     <asp:ListItem Text="2"/>
     <asp:ListItem Text="3"/>
    </asp:checkboxList>
    <asp:CheckBox id="cb" runat="server" Text="Select All" AutoPostBack="true" OnCheckedChanged="CheckList"/>
    </form>
    <script language="C#" runat="server">
    void CheckList(Object sender, EventArgs e)
    {
      foreach(ListItem li in clb.Items)
      {
         li.Selected = cb.Checked;  
      }
    }
    </script>