ASP.Net c# 选择给定 GroupName 中的哪个单选按钮? [英] ASP.Net c# Which radio button in a given GroupName is selected?

查看:37
本文介绍了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 中的哪个单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆