本文介绍了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;
}

推荐答案

您必须检查所有单选按钮的选中属性.
没有简单的方法可以通过groupName进行检查.(您可以编写一种方法来扫描某个控件容器中的所有单选按钮,并返回对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中选择了哪个单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 18:30