我在我的网页上有一个CheckBox
和一个CheckBox
列表。
如果CheckBox
被选中,在CheckBoxList
所有CheckBoxes
应该得到,而如果选择的CheckBox
未被选中,同样都在CheckBox
的CheckBoxes
应该得到取消选中状态(未选中)。选择CheckBoxList中的所有复选框
的.aspx代码
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem>Item A</asp:ListItem>
<asp:ListItem>Item B</asp:ListItem>
<asp:ListItem>Item C</asp:ListItem>
<asp:ListItem Selected="True">Item D</asp:ListItem>
<asp:ListItem>Item E</asp:ListItem>
<asp:ListItem>Item F</asp:ListItem>
<asp:ListItem>Item G</asp:ListItem>
</asp:CheckBoxList>
<asp:CheckBox ID="allChkBox" Text="Select all" runat="server"
oncheckedchanged="allChkBox_CheckedChanged" />
我试图做服用点这样的,但它didb't工作:
bool prevSelection = false;
protected void allChkBox_CheckedChanged(object sender, EventArgs e)
{
if (!prevSelection)
{
foreach (ListItem chkitem in CheckBoxList1.Items)
{
chkitem.Selected = true;
}
}
else
{
foreach (ListItem chkitem in CheckBoxList1.Items)
{
chkitem.Selected = false;
}
}
prevSelection = !prevSelection;
}
你能提供你的aspx代码? – 2012-03-06 03:09:12
@ Thit Lwin Oo:新增 – Cipher 2012-03-06 03:11:57
好的..其他人提供了答案。我会建议..你应该在客户端JavaScript中做到这一点,并且不需要回发。 – 2012-03-06 03:21:10