Controls You Can Use on Web Forms ASP.NET Standard Controls RadioButton and RadioButtonList Controls
You can add radio buttons to a Web Forms page in two ways:
- By adding individual RadioButton Web server controls and grouping them.
- By adding a RadioButtonList control and adding individual list items to the control.
NOTE: This topic addresses how to add individual RadioButton controls to the page. For details about adding a RadioButtonList control, see Adding RadioButtonList Controls to a Web Forms.
For details about the differences in these approaches, see Introduction to the RadioButton and RadioButtonList Controls.
When you use individual RadioButton Web server controls, you typically add a set of them to the page and then group them. You can create multiple separate groups of buttons.
- Declare an <
asp:RadioButton
> element on the page. For syntax, see RadioButton Control Syntax.
- Specify a caption by setting the control’s Text property.
- Optionally change the orientation of the caption by setting the TextAlign property.
<asp:RadioButton id="Radio1" Text="button caption here" runat="server" />
- Set the GroupName property of each control to the same name. You can use any string as the name, but do not include a space. For example, you might assign the string
RadioGroup1
to the GroupName property of all the buttons.
<asp:RadioButton id="Radio1" Text="button caption here" GroupName="RadioGroup1"
runat="server" />
To create multiple groups, use a different group name for each.
NOTE: You can add RadioButton controls to the page and group them with existing groups at any point.
Setting and Getting the Selection in a RadioButton Control Responding to a User Selection in a RadioButton Group