.net listview 查找每一行中是否至少选择了一个单选框

发布于 2024-08-07 03:55:10 字数 227 浏览 1 评论 0原文

我有一个列表视图,每一行都有 2 个或更多单选按钮控件,我想查明在提交时是否至少选择了一个单选按钮。

例如

第 1 行 问题1 单选按钮1 单选按钮2 单选按钮

3 第 2 行 问题2 单选按钮1 单选按钮2 提交时的radiobutton3

我想查明用户是否在每一行上检查了至少一个单选按钮

i have a listview with 2 or more radio button controls in each row of it and i want to findout if atleast one radiobutton selected on submit.

for example

ROW 1
Quetison 1
radiobutton1
radiobutton2
radiobutton3

ROW 2
Quetison 2
radiobutton1
radiobutton2
radiobutton3

on submit i want to findout if user checked atleast one radiobutton on each ROW

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云裳 2024-08-14 03:55:10

对于 Asp.Net ListView:

foreach(ListViewDataItem myItem in myListView.Items)
{
   RadioButton btn1 = (RadioButton)myItem.FindControl("radiobutton1");
   RadioButton btn2 = (RadioButton)myItem.FindControl("radiobutton2");
   RadioButton btn3 = (RadioButton)myItem.FindControl("radiobutton3");

   bool AtLeastOneChecked = btn1.Checked || btn2.Checked || btn3.Checked; 

}

新方法 - 不知道单选按钮的数量

  foreach(ListViewDataItem myItem in myListView.Items)
{
   bool AtLeastOneChecked = false;
   foreach(Control myControl in myItem.Controls)
   {
      try
      {
         RadioButton rdoTemp = (RadioButton)myControl;
         AtLeastOneChecked = rdoTemp.Checked;
      }
      catch (Exception)
      {
          // do nothing - this probably wasn't a radio button control and errored out onthe conversion
      }
   }    
}

for an Asp.Net ListView:

foreach(ListViewDataItem myItem in myListView.Items)
{
   RadioButton btn1 = (RadioButton)myItem.FindControl("radiobutton1");
   RadioButton btn2 = (RadioButton)myItem.FindControl("radiobutton2");
   RadioButton btn3 = (RadioButton)myItem.FindControl("radiobutton3");

   bool AtLeastOneChecked = btn1.Checked || btn2.Checked || btn3.Checked; 

}

New approach - not knowing the # of radio buttons

  foreach(ListViewDataItem myItem in myListView.Items)
{
   bool AtLeastOneChecked = false;
   foreach(Control myControl in myItem.Controls)
   {
      try
      {
         RadioButton rdoTemp = (RadioButton)myControl;
         AtLeastOneChecked = rdoTemp.Checked;
      }
      catch (Exception)
      {
          // do nothing - this probably wasn't a radio button control and errored out onthe conversion
      }
   }    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文