Data Binding to an ArrayList
An ArrayList object may generate the text and values to the controls:
- asp:RadioButtonList, which represents a list control that encapsulates a group of radio button controls
- asp:CheckBoxList, which creates a multi selection check box group that can be dynamically created by binding the control to a data source
- asp:DropDownList, which represents a control that allows the user to select a single item from a drop-down list
- asp:Listbox, which implements a list of selectable items
To bind data to a RadioButtonList control, first create a RadioButtonList control (without any asp:ListItem elements) in a page:
<asp:RadioButtonList id="rb" AutoPostBack="True"
onSelectedIndexChanged="DisplayMessage" runat="server" />
AutoPostBack
property gets or sets a value indicating whether a postback to the server automatically occurs when the user changes the list selection.
OnSelectedIndexChanged
method raises the SelectedIndexChanged
event.
This allows you to provide a custom handler for the event.
SelectedItem
property gets the selected item with the lowest index in the list control.
Then add the script that builds the list and binds the values in the list to the RadioButtonList.
The DataSource
property of the RadioButtonList is set to the ArrayList and it defines the data source of the RadioButtonList.
The DataBind
method of the RadioButtonList control binds the data source with the RadioButtonList.