一个 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.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实现,如何实现呢?
<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>