How to: Add Individual RadioButton Web Server Controls to a Web Forms Page
You can add a radio button to a Web Forms page in two ways:
-
By adding an individual RadioButton Web server control.
-
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 information about adding items to a RadioButtonList control, see How to: Add Items in List Web Server 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.
To add individual RadioButton controls to a Web Forms page
-
Type an <asp:RadioButton> element onto the page. For syntax, see RadioButton Web Server Control.
-
Specify a caption by setting the Text property.
Note CheckBox is the base class for RadioButton.
-
Optionally, change the orientation of the caption by setting the TextAlign property.
-
Repeat steps 1 through 3 for each radio button.
To group individual RadioButton controls
-
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 "RadioButtonGroup1" to the GroupName property of all the buttons.
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.