RadioButtonList

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 panel to your page.

To bind the RadioButtonList control to a data source

  1. In Design view, right-click the RadioButtonList control, and then click ShowCommon 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 fieldto displayin 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 ShowCommon 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 Cc295394.xtlink_newWindow(en-us,Expression.40).png in the MSDN library.

RadioButton Control vs. RadioButtonList Control

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 Cc295394.xtlink_newWindow(en-us,Expression.40).png in the MSDN library.

Note

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.

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.