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?
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 ...
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...
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.
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.
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>
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With