<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHeader" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderForTitleAndIntro" Runat="Server">
<table width="100%" cellpadding="2" cellspacing="0">
<tr valign="top" class="ArticleTitle">
<td style="padding-left:10px;" valign="middle">
asp:RadioButtonList control</td>
</tr>
<tr>
<td class="ArticleContents">
RadioButtonList control is a single control that groups a collection of radiobuttons, all are rendered through an individual <input type=radio></input>.
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderForContents" Runat="Server">
<asp:Label ID="lblError" runat="server" SkinID="ErrorLabel" EnableViewState="False"></asp:Label>
<div class="ArticleContents">
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 <span class="DemoCP">BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. </span>
are implemented through style properites of <input>.
<p> </p>
Following are some important properties that are very useful.<br />
(RadioButtonList controls supports the same set of properties as the CheckBoxList control does.
<table width="100%" class="TutoPropPlaceHolder" border="1" cellpadding="2" cellspacing="1">
<tr>
<td class="DemoCP">SelectedValue</td>
<td>
Get the value first selected item.
</td>
</tr>
<tr>
<td class="DemoCP">SelectedIndex</td>
<td>
Gets or Sets the index of the first selected item.
</td>
</tr>
<tr>
<td class="DemoCP">SelectedItem</td>
<td>
Gets the first selected item
</td>
</tr>
<tr>
<td class="DemoCP">TextAlign</td>
<td>
Gets or Sets the alignment of the radiobutton text.
</td>
</tr>
<tr>
<td class="DemoCP">DataTextField</td>
<td>
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.)
</td>
</tr>
<tr>
<td class="DemoCP">DataValueField</td>
<td>
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.)
</td>
</tr>
<tr>
<td class="DemoCP">DataSourceID</td>
<td>
ID of the datasource component to provide data. (Only used when you have any DataSource component on the page, like SqlDataSource, AccessDataSource etc.)
</td>
</tr>
<tr>
<td class="DemoCP">DataSource</td>
<td>
The datasource that populates the items in the radiobuttonlist. (Generally used when you are dynamically generating the items from Database.)
</td>
</tr>
<tr>
<td class="DemoCP">AutoPostBack</td>
<td>
true/false. If true, the form is automatically posted back to the server when user click any of the radiobutton. It will also fire <span class="DemoCP">OnSelectedIndexChanged</span> method.
</td>
</tr>
<tr>
<td class="DemoCP">AppendDataBoundItems</td>
<td>
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.
</td>
</tr>
<tr>
<td class="DemoCP">OnSelectedIndexChanged</td>
<td>
Method name that fires when user click any of the radiobutton in the list. (Fires only when AutoPostBack=true.)
</td>
</tr>
<tr>
<td class="DemoCP">Items</td>
<td>
Gets the colleciton of the items from the list.
</td>
</tr>
<tr>
<td class="DemoCP">RepeatLayout</td>
<td>
table/flow. Gets or Set the layout of the radiobuttons when rendered to the page.
</td>
</tr>
<tr>
<td class="DemoCP">RepeatColumns</td>
<td>
Get or Sets the no. of columns to display when the control is rendered.
</td>
</tr>
<tr>
<td class="DemoCP">RepeatDirection</td>
<td>
Horizontal/Vertical. Gets or Sets the the value to indicate whether the control will be rendered horizontally or vertically.
</td>
</tr>
</table>
<!-- START - Demo Section -->
<table class="DemoPlaceHolder" border="1" cellpadding="2" cellspacing="4">
<tr>
<td class="DemoTitle">
DEMO : RadioButtonList
</td>
<td align="right">
<a class="DemoShowSource" href="../../misc/codeviewer/default.aspx?pagename=~/tutorials/controls/radiobuttonlist.aspx" target="_blank">Show Source Code</a>
</td>
</tr>
<tr valign="Top">
<td>
<table width="100%" cellpadding="2" cellspacing="1">
<tr valign="Top">
<td style="width:40%;">
1st RadioButton List<br />
<asp:RadioButtonList ID="RadioButtonList1" runat="Server">
<asp:ListItem Text="Red" Value="red" Selected="True"></asp:ListItem>
<asp:ListItem Text="Blue" Value="blue"></asp:ListItem>
<asp:ListItem Text="Green" Value="green"></asp:ListItem>
</asp:RadioButtonList>
4th RadioButton List, This will fire OnSelectedIndexChanged event<br />
<asp:RadioButtonList ID="RadioButtonListBoundFire" runat="Server" DataTextField="Name" DataValueField="ID" OnSelectedIndexChanged="FireOnSelectedIndexChangd" AutoPostBack="true" RepeatColumns="3" />
</td>
<td>
2nd RadioButton List<br />
<asp:RadioButtonList ID="RadioButtonRunTime" runat="server" />
</td>
<td>
3rd RadioButton List<br />
<asp:RadioButtonList ID="RadioButonListBind" runat="Server" DataTextField="Name" DataValueField="ID" RepeatColumns="2" />
</td>
</tr>
</table>
</td>
<td>
<asp:Label ID="lblLabel" runat="server" EnableViewState="False"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
<!-- START - Server Side Code -->
<pre>
// 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" />
</pre>
<!-- END - Server Side Code -->
</td>
</tr>
</table>
<!-- END - Demo Section -->
</div>
<br />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PlaceHolderFooter" Runat="Server">
</asp:Content>
Go Top