Export (0) Print
Expand All

RadioButtonList control

The RadioButtonList control represents a list control that encapsulates a group of radio button controls.

You can use two types of ASP.NET controls to add radio buttons to a page: individual RadioButton controls or a RadioButtonList control. Both controls allow users to select from a small set of mutually exclusive, predefined choices. The controls allow you to define any number of radio buttons with labels and to arrange them horizontally or vertically.

To add a RadioButtonList control to a page

  • Drag the RadioButtonList control from the Toolbox task pane to your page.

To bind the RadioButtonList control to a data source

  1. In Design view, right-click the RadioButtonList control, and then click Show Common Control Tasks.

  2. On the Common RadioButtonList Tasks menu, click Choose Data Source.

  3. In the Data Source Configuration Wizard, choose a source for the RadioButtonList control in the Select a data source dropdown. In the Select a data field to display in the RadioButtonList dropdown, select the field for the text that the user will see. In the Select a data field for the value of the RadioButtonList dropdown, select the field for the data that can be programmatically accessed when the user chooses an item in the list.

To define items for the RadioButtonList control

  1. In Design view, right-click the RadioButtonList control, and then click Show Common Control Tasks.

  2. On the Common RadioButtonList Tasks menu, click Edit Items.

  3. In the ListItem Collection Editor dialog box, click Add to add an item.

  4. In the ListItem properties area, set the Text and Value properties.

  5. Repeat steps 3 and 4 until you have added all the items you want.

For a full description of all RadioButtonList control properties, see RadioButtonList Properties in the MSDN library.

You add individual RadioButton controls to a page and work with them singly. Typically, you group two or more individual buttons together.

In contrast, the RadioButtonList control is a single control that acts as a parent control for a collection of radio button list items.

Each type of control has advantages. Individual RadioButton controls give you more control over the layout of the radio button group. For example, you can include text (that is, non-radio-button text) between radio buttons.

The RadioButtonList control does not permit you to insert text between the buttons, but is far easier to use if you want to bind the buttons to a data source. It is also slightly easier to write code that determines which button has been selected.

The RadioButtonList control raises a SelectedIndexChanged event when users change which radio button in the list is selected. By default, the event does not cause the form to be posted to the server, although you can specify this option by setting the AutoPostBack property to true. For details, see How to: Respond to a User Selection in a RadioButton Web Server Control Group in the MSDN library.

Cc295394.alert_note(en-us,Expression.10).gifNote:

The ability of a RadioButtonList control to post to the server when it is selected requires that the browser support ECMAScript (JScript, JavaScript) and that scripting be enabled on the user's browser.

Community Additions

ADD
Show:
© 2014 Microsoft