![](/img/trans.png)
[英]using javascript to loop through asp.net radio button list to get selected value and text
[英]Get selected radio button not in a list in ASP .NET
我有一些属于一个组的单选按钮。 我没有将它们放在列表中,因为它们都散落在页面周围。 如何轻松获取所选单选按钮?
也许不是最快的方式,但这样的事情应该有效:
private RadioButton GetSelectedRadioButton(string groupName)
{
return GetSelectedRadioButton(Controls, groupName);
}
private RadioButton GetSelectedRadioButton(ControlCollection controls, string groupName)
{
RadioButton retval = null;
if (controls != null)
{
foreach (Control control in controls)
{
if (control is RadioButton)
{
RadioButton radioButton = (RadioButton) control;
if (radioButton.GroupName == groupName && radioButton.Checked)
{
retval = radioButton;
break;
}
}
if (retval == null)
{
retval = GetSelectedRadioButton(control.Controls, groupName);
}
}
}
return retval;
}
使用“GroupName”属性将单选按钮分组到一个组中。 这将使他们表现为一个群体。 您仍然需要单独查询它们以查看已检查状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.