asp.net.ph

Skip Navigation Links

Setting and Getting the Selection in a RadioButton Control

Controls You Can Use on Web Forms   ASP.NET Standard Controls   RadioButton and RadioButtonList Controls


You can set a selected radio button at design time or at run time in code. If the radio button is in a group, setting it clears any other selection in the group.

NOTE: If you are working with a RadioButtonList control, the procedure for getting and setting the value of a button is different. For details, see Determining the Selection in a List Control and Setting the Selection in a List Control.

To set the selected RadioButton control

  • Set the control’s Checked property to true. If you select more than one RadioButton control in a group, the browser determines which button is rendered as selected.
<asp:RadioButton id="Radio1" Checked=true Text="Typical" runat="server" />

If you set the property to false, it clears the selection but does not select another radio button. Therefore, you can clear all selections by setting the Checked property of all radio buttons in a group to false.

Determining which RadioButton control has been selected is a matter of testing the Checked property.

To determine which RadioButton control in a group is selected

  • Test the control’s Checked property.

NOTE: Testing the value of a radio button does not tell you if the user changed the value of the control, only if it is selected. To check for a change in the control, write an event-handling method for the control’s CheckedChanged event. For details, see Responding to a User Selection in a RadioButton Group.

To determine which is checked in a group, you have to test each control individually, as in the following example:

void getSelected ( object src, EventArgs e ) {
   String msg = "You selected ";
   if ( Radio1.Checked )
      msg += Radio1.Text;
   else if ( Radio2.Checked )
      msg += Radio2.Text;
   else if ( Radio3.Checked )
      msg += Radio3.Text;

   Label1.Text = msg;
}
  C# VB
RadioButton1.aspx
Run Sample | View Source
See Also

Adding Individual RadioButton Controls to a Web Forms Page   Responding to a User Selection in a RadioButton Group



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note