Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP.NET SortedList

ASP.NET Web Forms - SortedList Object


The SortedList object combines the features of the ArrayList object and the Hashtable object.


Try it - Example

SortedList RadiobuttonList 1

SortedList RadiobuttonList 2

SortedList DropDownList


SortedList Object

The SortedList object contains items represented by key/value pairs. The SortedList object automatically sorts items in alphabetical or numerical order.

Add items to a SortedList using the Add() method. Adjust the SortedList to its final size using the TrimToSize() method.

The code below creates a SortedList object named mycountries and adds four elements:


Data Binding

The SortedList object can automatically generate text and values for the following controls:

To bind data to a RadioButtonList control, first create a RadioButtonList control in the .aspx page (without any asp:ListItem elements):

Then add the script that creates the list and binds the values in the list to the RadioButtonList control:

Then we add a subroutine that is executed when the user clicks an item in the RadioButtonList control. When a radio button is clicked, a line of text appears in the label:

Example

AutoPostBack="True" onSelectedIndexChanged="displayMessage" />

Demo Example »