一个 checkbox,text = all and autopostback= true. 一个checkboxlist(动态绑定),autopostback= false。
需求
1.check checkbox, 选中所有checkboxlist 的item. 这个比较好实现.
  protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
  {
  foreach (ListItem item in CheckBoxList1.Items)
  item.Selected = (sender as CheckBox).Checked;
  }2.如果checkbox和所有checkboxlist item是选中状态,uncheck一个 checkgoxlist item,checkbox 的选中状态改变成unchecked. 因为checkboxlist autopostback =false, 我想是应该用javascript实现,如何实现呢?

解决方案 »

  1.   

    居然是半夜发的给ListItem添加客户端(js)的点击(选中)事件,,,然后再js中找到那个text=all的Checkbox,控制它的选中状态其实这种checkbox用name来区别比较好控制一点
      

  2.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-1.8.0.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                $("#chkAll").click(function () {
                    $("#chkList input[type='checkbox']").prop("checked", $(this).prop("checked"));
                });
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:CheckBox ID="chkAll" Text="All" runat="server" />
            <asp:CheckBoxList ID="chkList" runat="server">
                <asp:ListItem Text="text1" />
                <asp:ListItem Text="text2" />
            </asp:CheckBoxList>
        </div>
        </form>
    </body>
    </html>
      

  3.   

    你的code不工作阿,还有我的checkboxlist 是数据绑定的。我在codebehind file里写了点code,能实现这样的功能,不过就是click 每一个checkbox都要postback,好像很不专业。