我有一个列表视图,每行有两个或更多单选按钮控件,我想知道在提交时是否选择了至少一个单选按钮。
例如
行1 Quetison 1 radiobutton1 radiobutton2 radiobutton3
行2 Quetison 2 radiobutton1 radiobutton2 radiobutton3
在提交时我想知道用户是否在每个ROW上检查了至少一个radiobutton
答案 0 :(得分:3)
用于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
}
}
}