-3

我希望多个单选按钮位于同一组中。谁能帮帮我吗?

4

3 回答 3

0

利用asp:RadioButtonList

<asp:RadioButtonList ID="rblMyList" runat="server">
    <asp:ListItem Text="Male" Value="Male"></asp:ListItem>
    <asp:ListItem Text="Female" Value="Female"></asp:ListItem>
</asp:RadioButtonList>
于 2013-11-01T05:20:05.563 回答
0

试试这个以获得具有相同组名的 Radiobutton

C#:

 int count = 0;
        foreach (RadioButton rb in divContainer.Controls.OfType<System.Web.UI.WebControls.RadioButton>())
        {
            if(rb.GroupName=="a")
            {
                count++;
            }
        }

注意:asp:RadioButtonList 也是更好的选择

于 2013-11-01T06:02:09.113 回答
0

试试这个:(基于Renju vinod回答这个

    public IEnumerable<Control> GetAll(Control control, Type type)
    {
        var controls = control.Controls.Cast<Control>();
        return controls.SelectMany(ctrls => GetAll(ctrls, type)).Concat(controls).Where(c => c.GetType() == type);
    }

现在你可以像下面这样得到这个

        string GroupName = "MyGroupName"; // Your known group name
        int numberOfRadioOfThisGroup = 0;
        var cntls = GetAll(this, typeof(RadioButton));
        foreach (Control cntrl in cntls)
        {
            RadioButton rb = (RadioButton)cntrl;
            if (rb.GroupName == GroupName)
            {
                numberOfRadioOfThisGroup++;
            }
        }

        // numberOfRadioOfThisGroup will now have the count of number of radiobuttons belonging to your group
于 2013-11-01T06:07:23.577 回答