【发布时间】:2011-08-09 14:32:42
【问题描述】:
我有两个asp:RadioButton 控件具有相同的GroupName,这基本上使它们相互排斥。
我的标记:
<asp:RadioButton ID="OneJobPerMonthRadio" runat="server"
CssClass="regtype"
GroupName="RegistrationType"
ToolTip="125"/>
<asp:RadioButton ID="TwoJobsPerMonthRadio" runat="server"
CssClass="regtype"
GroupName="RegistrationType"
ToolTip="200"/>
我的目的是找到选中的 RadioButton 的工具提示/文本。我有这个代码隐藏:
int registrationTypeAmount = 0;
if (OneJobPerMonthRadio.Checked)
{
registrationTypeAmount = Convert.ToInt32(OneJobPerMonthRadio.ToolTip);
}
if (TwoJobsPerMonthRadio.Checked)
{
registrationTypeAmount = Convert.ToInt32(TwoJobsPerMonthRadio.ToolTip);
}
我发现该代码丑陋且多余。 (如果我有 20 个复选框呢?)
有没有一种方法可以从一组具有相同GroupName 的 RadioButtons 中获取选中的RadioButton?如果没有,写一个的指针是什么?
P.S:在这种情况下我不能使用RadioButtonList。
【问题讨论】:
标签: c# asp.net linq radio-button