Getting Started with the Telerik WebForms RadioButtonList
The following help article demonstrates how to set up a page with a RadRadioButtonList control and use its OnSelectedIndexChanged server event:
-
In the default page of a new ASP.NET AJAX-enabled Web Application, add a RadRadioButtonList control:
ASP.NET
<telerik:RadRadioButtonList ID="RadRadioButtonList1" runat="server"> </telerik:RadRadioButtonList>
-
Add two
RadioButtonListItem
objects to theItems
collection and set the appropriate values forText
andSelected
properties of each item:ASP.NET
<telerik:RadRadioButtonList ID="RadRadioButtonList1" runat="server"> <Items> <telerik:RadioButtonListItem Text="Accept" Value="0" Selected="true" /> <telerik:RadioButtonListItem Text="Decline" Value="1" /> </Items> </telerik:RadRadioButtonList>
-
To hook to the OnSelectedIndexChanged server-side event of RadRadioButtonList, add an attribute to the main control tag and add the method signature:
ASP.NET
<telerik:RadRadioButtonList ID="RadRadioButtonList1" runat="server" OnSelectedIndexChanged="RadRadioButtonList1_SelectedIndexChanged"> <Items> <telerik:RadioButtonListItem Text="Accept" Value="0" Selected="true" /> <telerik:RadioButtonListItem Text="Decline" Value="1" /> </Items> </telerik:RadRadioButtonList>
C#
protected void RadRadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { }
VB.NET
Protected Sub RadRadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) End Sub
-
Add a Label control to write the information to:
ASP.NET
<asp:Label ID="Label1" Text="" runat="server" />
-
Use the OnSelectedIndexChanged event handler to write information about the properties of the
SelectedItem
of theRadRadioButtonList
:C#
protected void RadRadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { RadRadioButtonList radioButtonList = sender as RadRadioButtonList; string data = string.Format("selected index: {0}, selected value {1}, selected text: {2}", radioButtonList.SelectedIndex, radioButtonList.SelectedValue, radioButtonList.SelectedItem.Text); Label1.Text = data; }
VB.NET
Protected Sub RadRadioButtonList1_SelectedIndexChanged(sender As Object, e As EventArgs) Dim radioButtonList As RadRadioButtonList = TryCast(sender, RadRadioButtonList) Dim data As String = String.Format("selected index: {0}, selected value {1}, selected text: {2}", radioButtonList.SelectedIndex, radioButtonList.SelectedValue, radioButtonList.SelectedItem.Text) Label1.Text = data End Sub