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 中的哪个单选按钮?
基础教程推荐
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
