New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Getting Started with the Telerik WebForms CheckBoxList
The following help article demonstrates how to set up a page with a RadCheckBoxList control and use its OnSelectedIndexChanged server event:
-
In the default page of a new ASP.NET AJAX-enabled Web Application, add a RadCheckBoxList control:
ASP.NET<telerik:RadCheckBoxList ID="RadCheckBoxList1" runat="server"> </telerik:RadCheckBoxList>
-
Add two
ButtonListItem
objects to theItems
collection and set the appropriate values forText
andSelected
properties of each item:ASP.NET<telerik:RadCheckBoxList ID="RadCheckBoxList1" runat="server"> <Items> <telerik:ButtonListItem Text="Accept" Value="0" Selected="true" /> <telerik:ButtonListItem Text="Decline" Value="1" /> </Items> </telerik:RadCheckBoxList>
-
To hook to the OnSelectedIndexChanged server-side event of RadCheckBoxList, add an attribute to the main control tag and add the method signature:
ASP.NET<telerik:RadCheckBoxList ID="RadCheckBoxList1" runat="server" OnSelectedIndexChanged="RadCheckBoxList1_SelectedIndexChanged"> <Items> <telerik:ButtonListItem Text="Accept" Value="0" Selected="true" /> <telerik:ButtonListItem Text="Decline" Value="1" /> </Items> </telerik:RadCheckBoxList>
C#protected void RadCheckBoxList1_SelectedIndexChanged(object sender, EventArgs e) { }
VB.NETProtected Sub RadCheckBoxList1_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 theRadCheckBoxList
:C#protected void RadCheckBoxList1_SelectedIndexChanged(object sender, EventArgs e) { RadCheckBoxList checkboxlist = sender as RadCheckBoxList; string data = string.Format("selected index: {0}, selected value {1}, selected text: {2}", checkboxlist.SelectedIndex, checkboxlist.SelectedValue, checkboxlist.SelectedItem.Text); Label1.Text = data; }
VB.NETProtected Sub RadCheckBoxList1_SelectedIndexChanged(sender As Object, e As EventArgs) Dim checkboxlist As RadCheckBoxList = TryCast(sender, RadCheckBoxList) Dim data As String = String.Format("selected index: {0}, selected value {1}, selected text: {2}", checkboxlist.SelectedIndex, checkboxlist.SelectedValue, checkboxlist.SelectedItem.Text) Label1.Text = data End Sub