Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Radio Buttons ASP.NET C#

Tags:

c#

asp.net

I have two radio buttons for metric and US measurements. I load the page so the metric radio button is clicked. How do I set the two buttons so when US is clicked metric unclicks and vise versa?

like image 568
Mike Avatar asked Feb 28 '11 17:02

Mike


People also ask

How to add radio radio button in ASP NET?

RadioButton in ASP.NET Step 1: We have a toolbox in ASP.NET so first we need to drag the given ‘radiobutton’ control in the web form from the... Step 2: After adding the Radiobutton, we need to change the ‘text’ property by clicking on the Radiobutton control’. We... Step 3: Now repeat the same ...

What is radiobutton in MVC?

RadioButton is a kind of toggle control which receives the input from a user in the form of a click. In radio-button, all buttons are connected with the same group name and id. User can select any one button option from the given radiobuttons or list. In ASP.NET MVC, there are three ways to create a RadioButton...

What are the different syntaxes for radio button control?

There are two different syntaxes for Radio Button Control one is for RadioButton control and the other one is for RadioButtonList. Let us see some of the important properties of Radio button control Text: It is used to add the text for the radio button control. Items: Individual radio buttons are added to the control.

How to make a group of radio buttons with same name?

RadioButton control lets you make a group of radio buttons with other RadioButton. If you set it's GroupName property same for multiple radio buttons then all radio buttons with same name act as a single group. Within a group you can only select one RadioButton at a time. RadioButton group work as like RadioButtonList.


2 Answers

In order to make it work, you have to set property GroupName of both radio buttons to the same value:

<asp:RadioButton id="rbMetric" runat="server" GroupName="measurementSystem"></asp:RadioButton> <asp:RadioButton id="rbUS" runat="server" GroupName="measurementSystem"></asp:RadioButton> 

Personally, I prefer to use a RadioButtonList:

<asp:RadioButtonList ID="rblMeasurementSystem" runat="server">     <asp:ListItem Text="Metric" Value="metric" />     <asp:ListItem Text="US" Value="us" /> </asp:RadioButtonList> 
like image 83
bloparod Avatar answered Sep 21 '22 23:09

bloparod


Make sure their GroupName properties are set to the same name:

<asp:RadioButton GroupName="MeasurementSystem" runat="server" Text="US" /> <asp:RadioButton GroupName="MeasurementSystem" runat="server" Text="Metric" /> 
like image 29
RQDQ Avatar answered Sep 24 '22 23:09

RQDQ