ASP.Net c# Which radio button in a given GroupName is selected?(ASP.Net c# 选择给定 GroupName 中的哪个单选按钮?)
问题描述
我有 30 个单独的 RadioButton.我不能使用 RadioButtonList.有 3 组按钮.每个组都有一个唯一的 GroupName.一切都在网络浏览器中正常工作.我如何在回帖中知道在每个给定的 GroupsNames 中选择了哪个按钮?
I have 30 individual RadioButtons. I can not use a RadioButtonList. There are 3 groups of buttons. Each group has a unique GroupName. Everything works properly in the web browser. How can i tell on a post back which button is selected within each of the given GroupsNames?
我使用的功能
private string getRadioValue(ControlCollection clts, string groupName)
{
string ret = "";
foreach (Control ctl in clts)
{
if (ctl.Controls.Count != 0)
{
if (ret == "")
ret = getRadioValue(ctl.Controls, groupName);
}
if (ctl.ToString() == "System.Web.UI.WebControls.RadioButton")
{
RadioButton rb = (RadioButton)ctl;
if (rb.GroupName == groupName && rb.Checked == true)
ret = rb.Attributes["Value"];
}
}
return ret;
}
推荐答案
你必须检查所有radiobuttons的checked属性.
没有简单的方法可以通过 groupName 来检查它.(您可以编写方法来扫描某个控件容器中的所有单选按钮并返回组名对列表,控件已检查,但更容易扫描所有 rb)
You have to check all radiobuttons checked property.
There is no simple way to check it by groupName. (you can write method that scan all radiobuttons in some control container and return list of pairs groupName, control checked, but easier is to scan all rb)
这篇关于ASP.Net c# 选择给定 GroupName 中的哪个单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ASP.Net c# 选择给定 GroupName 中的哪个单选按钮?
基础教程推荐
- 将数据集转换为列表 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 如果条件可以为空 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
