ASP. NET Web Forms-SortedList object, formssortedlist
ASP. NET Web Forms-SortedList object
SortedList objects combine the features of ArrayList objects and Hashtable objects.
SortedList object
The SortedList object contains items represented by key/value pairs. SortedList objects are automatically sorted in alphabetical or numerical order.
Use the Add () method to Add a project to SortedList. Adjust SortedList to the final size using the TrimToSize () method.
The following code 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:
AutoPostBack = "True" onSelectedIndexChanged = "displayMessage"/>
Asp: RadioButtonList
Asp: CheckBoxList
Asp: DropDownList
Asp: Listbox
To bind data to the RadioButtonList control, you must first create a RadioButtonList control (without any asp: ListItem element) on the. aspx page ):
Then add the script for creating the list and bind the values in the list to the RadioButtonList control:
Then we add a child routine. When you click a project in the RadioButtonList control, the child routine will be executed. When a single-choice button is clicked, a line of text appears in the label.
<Script runat = "server">
Sub Page_Load
If Not Page. IsPostBack then
Dim mycountries = New SortedList
Mycountries. Add ("N", "Norway ")
Mycountries. Add ("S", "Sweden ")
Mycountries. Add ("F", "France ")
Mycountries. Add ("I", "Italy ")
Rb. DataSource = mycountries
Rb. DataValueField = "Key"
Rb. DataTextField = "Value"
Rb. DataBind ()
End if
End sub
Sub displayMessage (s as Object, e As EventArgs)
Lbl1.text = "Your favorite country is:" & rb. SelectedItem. Text
End sub
</Script>