如何检查和取消选中asp.net中的checkboxlist中的all [英] how to check and uncheck all in checkboxlist in asp.net
本文介绍了如何检查和取消选中asp.net中的checkboxlist中的all的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
h to all,
如何检查和取消选中asp.net中的复选框列表
设计: -
h to all,
how to check and uncheck in checkbox list in asp.net
Design:-
<asp:CheckBoxList ID="lst" runat="server" AutoPostBack="true" SelectionMode="Multiple" AppendDataBoundItems="true" DataTextField="BranchName" DataValueField="Branchcode" OnSelectedIndexChanged="lst_SelectedIndexChanged">
<asp:ListItem Text="All" Value="0" />
</asp:CheckBoxList>
用c#编码: -
And coding in c#:-
protected void lst_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem li in lstBranch.Items)
{
if (lstBranch.SelectedIndex == 0)
{
if (li.Text != "All")
{
li.Selected = true;
}
}
}
}
以上代码如果我勾选全部选中所有复选框列表。如果我取消勾选全部剩下的复选框应保持勾选但我需要取消所有然后所有想要取消勾选如果我勾选所有想要勾选并且多个也需要多个选择也不需要勾选全部
above code if i tick "ALL" all the checkbox list is selected. if i untick "ALL" remaining checkbox should remain in tick but i need if i untick all then all want to untick if i tick all want to tick and multiple also multiple selection also required without tick "ALL"
推荐答案
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="true" SelectionMode="Multiple" AppendDataBoundItems="true" DataTextField="BranchName" DataValueField="Branchcode" OnSelectedIndexChanged="lst_SelectedIndexChanged_1">
<asp:ListItem Text="All" Value="0" />
</asp:CheckBoxList>
<asp:CheckBoxList ID="lstMain" runat="server" AutoPostBack="true" SelectionMode="Multiple" AppendDataBoundItems="true" DataTextField="BranchName" DataValueField="Branchcode" OnSelectedIndexChanged="lst_SelectedIndexChanged">
<asp:ListItem Text="1" Value="0" />
<asp:ListItem Text="2" Value="0" />
<asp:ListItem Text="3" Value="0" />
</asp:CheckBoxList>
protected void lst_SelectedIndexChanged_1(object sender, EventArgs e)
{
if (CheckBoxList1.Items[0].Selected == true)
{
foreach (ListItem ls in lstMain.Items)
{
ls.Selected = true;
}
}
else
{
foreach (ListItem ls in lstMain.Items)
{
ls.Selected = false;
}
}
}
这篇关于如何检查和取消选中asp.net中的checkboxlist中的all的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文