The RadioButtonList control is similar to ChckBoxlist Control there you can select more than one item and here we user can select only one item from the list.
A radioButtonList control is written to the page in the following construction:
Figure Goes here…..
<asp:RadioButtonList ID="rdlNumber" AutoPostBack="true" runat="server"
onselectedindexchanged="rdlNumber_SelectedIndexChanged">
<asp:ListItem Text="One" />
<asp:ListItem Text="Two" />
<asp:ListItem Text="Three" />
<asp:ListItem Text="Four" />
</asp:RadioButtonList>
When we are playing on event handler for RadioButtonList control we need onselectedindexchanged event.
It looks like this
Figure goes here…..
.aspx
<form id="Form1" runat="server">
<div>
<asp:Label ID="lblHeader" ForeColor="Orange" Text="How many Children?" runat="server" />
<asp:RadioButtonList ID="rdlNumber" AutoPostBack="true" runat="server"
onselectedindexchanged="rdlNumber_SelectedIndexChanged">
<asp:ListItem Text="One" />
<asp:ListItem Text="Two" />
<asp:ListItem Text="Three" />
<asp:ListItem Text="Four" />
</asp:RadioButtonList>
<br />
<asp:Label ID="lblMessage" ForeColor="BlueViolet" runat="server" />
</div>
</form>
.cs
protected void rdlNumber_SelectedIndexChanged(object sender, EventArgs e)
{
lblMessage.Text = "You have selected " + rdlNumber.SelectedItem.ToString();
}
Have fun J
No comments:
Post a Comment