Monday, August 15, 2011

Select only one Radio button from each group on a single page

I need to display groups of radio buttons in a user control. I have used input radio button as I have to select only one choice in one group. How can I group these radio buttons into groups so that I can select one choice in each group.


Give them a GroupName to classify the radiobuttons in a group.

For example:

<asp:RadioButton id="Radio1" GroupName="RegularMenu"
             Text="Beef" BackColor="Pink" runat="server"/>

        <br />
        <asp:RadioButton id="Radio2" GroupName="RegularMenu"
             Text="Pork" BackColor="Pink" runat="server"/>

        <br />
        <asp:RadioButton id="Radio3" GroupName="RegularMenu"
             Text="Fish" BackColor="Pink" runat="server"/>

        <br />
        <asp:RadioButton id="Radio4" GroupName="vegetarianMenu"
             Text="Mushroom" BackColor="LightGreen" runat="server"/>

        <br />
        <asp:RadioButton id="Radio5" GroupName="vegetarianMenu"
             Text="Tofu" BackColor="LightGreen" runat="server"/>

        <br />
        <asp:Button id="Button1" OnClick="Button1_Click"
             Text="Regroup the radio buttons" runat="server"/>

No comments:

Post a Comment