RadioButtonList control is a single control that groups a collection of radiobuttons, all are rendered through an individual <input type=radio></input>.
Its properties like
BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc.
are implemented through style properites of <input>.
Following are some important properties that are very useful.
(RadioButtonList controls supports the same set of properties as the CheckBoxList control does.
SelectedValue |
Get the value first selected item.
|
SelectedIndex |
Gets or Sets the index of the first selected item.
|
SelectedItem |
Gets the first selected item
|
TextAlign |
Gets or Sets the alignment of the radiobutton text.
|
DataTextField |
Name of the data source field to supply the text of the items. (No need to set when you are adding items directly into .aspx page.)
|
DataValueField |
Name of the data source field to supply the value of the items. (No need to set when you are adding items directly into .aspx page.)
|
DataSourceID |
ID of the datasource component to provide data. (Only used when you have any DataSource component on the page, like SqlDataSource, AccessDataSource etc.)
|
DataSource |
The datasource that populates the items in the radiobuttonlist. (Generally used when you are dynamically generating the items from Database.)
|
AutoPostBack |
true/false. If true, the form is automatically posted back to the server when user click any of the radiobutton. It will also fire OnSelectedIndexChanged method.
|
AppendDataBoundItems |
true/false. If true, the statically added item (added from .aspx page) is maintained when adding items dynamically (from code behind file) or items are cleared.
|
OnSelectedIndexChanged |
Method name that fires when user click any of the radiobutton in the list. (Fires only when AutoPostBack=true.)
|
Items |
Gets the colleciton of the items from the list.
|
RepeatLayout |
table/flow. Gets or Set the layout of the radiobuttons when rendered to the page.
|
RepeatColumns |
Get or Sets the no. of columns to display when the control is rendered.
|
RepeatDirection |
Horizontal/Vertical. Gets or Sets the the value to indicate whether the control will be rendered horizontally or vertically.
|
DEMO : RadioButtonList
|
Show Source Code
|
|
|
// 1st RadioButtonList
<asp:RadioButtonList ID="RadioButtonList1" runat="Server">
<asp:ListItem Text="Red" Value="red"></asp:ListItem>
<asp:ListItem Text="Blue" Value="blue"></asp:ListItem>
<asp:ListItem Text="Green" Value="green"></asp:ListItem>
</asp:RadioButtonList>
// 2nd RadioButtonList
<asp:RadioButtonList ID="RadioButtonRunTime" runat="server" />
// 3rd RadioButtonList
<asp:RadioButtonList ID="RadioButonListBind" runat="Server" DataTextField="Name" DataValueField="ID" />
// 4th RadioButtonList
<asp:RadioButtonList ID="RadioButtonListBoundFire" runat="Server" DataTextField="Name" DataValueField="ID" OnSelectedIndexChanged="FireOnSelectedIndexChangd" AutoPostBack="true" />
|