Collecting RadioButtonList Controls

Learning Resources
 

Collecting RadioButtonList Controls


RadioButtonList Web Server Control

Creates a group of radio buttons. This control supports binding to a data source.



   


Remarks

The RadioButtonList control allows you to create a single-selection radio button group that can be dynamically generated by binding to a data source. To specify the items that you want to appear in the RadioButtonList control, place a ListItem element for each entry between the opening and closing tags of the RadioButtonList control.

Note   You can also use the RadioButton control. The RadioButtonList control is easier for creating a set of radio buttons using data binding, while an individual RadioButton control gives you greater control over layout.

The RadioButtonList control also supports data binding. To bind the control to a data source, first create a data source, such as a System.Collections.ArrayList object, that contains the items to display in the control. Next, use the Control.DataBind method to bind the data source to the RadioButtonList control. Use the DataTextField and DataValueField properties to specify which field in the data source to bind to the Text and Value properties, respectively, of each list item in the control. The RadioButtonList control will now display the information from the data source.

To determine the selected items in the RadioButtonList control, iterate through the Items collection and test the Selected property of each item in the collection.

You can specify the rendering of the list with the RepeatLayout and RepeatDirection properties. If RepeatLayout is set to RepeatLayout.Table (the default setting), the list will be rendered within a table. If it is set to RepeatLayout.Flow, the list will be rendered without any tabular structure. By default, RepeatDirection is set to RepeatDirection.Vertical. Setting this property to RepeatDirection.Horizontal will render the list horizontally.

CAUTION   Text is not HTML encoded before it is displayed in the RadioButtonList control. This makes it possible to embed script within HTML tags in the text. If the values for the control come from user input, be sure to validate the values to help prevent security vulnerabilities.
 
--MSDN
 For Support