C# 从ValidationGroup检索所选复选框值
我有一个页面,它根据数据库动态地用复选框填充listview。复选框的文本等于数据库中所有用户的用户名。我正在尝试创建一个控件,其中所选复选框中的用户名将被删除。为此,我计划使用foreach循环,该循环将针对ValidationGroup中的每个选中复选框运行 首先,这里是ASP.NET代码,显示了我格式化页面的方法C# 从ValidationGroup检索所选复选框值,c#,asp.net,sql-server,foreach,C#,Asp.net,Sql Server,Foreach,我有一个页面,它根据数据库动态地用复选框填充listview。复选框的文本等于数据库中所有用户的用户名。我正在尝试创建一个控件,其中所选复选框中的用户名将被删除。为此,我计划使用foreach循环,该循环将针对ValidationGroup中的每个选中复选框运行 首先,这里是ASP.NET代码,显示了我格式化页面的方法 <asp:ListView ID="lvUsers" runat="server"> <ItemTemplate>
<asp:ListView ID="lvUsers" runat="server">
<ItemTemplate>
<asp:CheckBox ID="chkUser" runat="server" Text='<%# Eval("UserName") %>' ValidationGroup="userCheck" /><br />
</ItemTemplate>
</asp:ListView>
在此方面的任何帮助都将不胜感激。使用Jimmy在中提供的nice ControlFinder类,您可以在ListView中递归检索复选框,并测试其
验证组
:
ControlFinder<CheckBox> finder = new ControlFinder<CheckBox>();
finder.FindChildControlsRecursive(lvUsers);
foreach (CheckBox chkBox in finder.FoundControls)
{
if (chkBox.Checked && chkBox.ValidationGroup == "userCheck")
{
// Do something
}
}
ControlFinder=newcontrolfinder();
finder.FindChildControlsRecursive(lvUsers);
foreach(finder.FoundControls中的chkBox复选框)
{
if(chkBox.Checked&&chkBox.ValidationGroup==“userCheck”)
{
//做点什么
}
}
谢谢,这是一个出色的实现,工作完美无瑕!这听起来对解决我的另一个问题也很有用,那就是从复选框中检索文本值。非常感谢你!
ControlFinder<CheckBox> finder = new ControlFinder<CheckBox>();
finder.FindChildControlsRecursive(lvUsers);
foreach (CheckBox chkBox in finder.FoundControls)
{
if (chkBox.Checked && chkBox.ValidationGroup == "userCheck")
{
// Do something
}
}