私はCheckBox
とCheckBox
のリストを私のWebページに持っています。 CheckBox
が選択されている場合
、CheckBoxList
内のすべてのCheckBoxes
は選択を取得する必要があり、かつCheckBox
がオフになっている場合に、CheckBox
でも同様に全てのCheckBoxes
は(チェック)選択解除する必要があります。CheckBoxListのすべてのチェックボックスを選択してください
<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" />
.aspxのコードは、私はこのようなsomehtingを実行してみましたが、それは仕事didb't:私はASPに手を出してきたので、それはしばらくしている
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コードを提供してもらえますか? –
@Thit Lwin Oo: – Cipher
を追加しました。他にも回答がありました。私はお勧めします..あなたはクライアントのjavascriptでこれを行う必要がありますポストバック。 –