ASP.NET Web Forms - Hashtable Object
The Hashtable object contains items represented by key/value pairs.
Try it - Example
Creating a Hashtable
The Hashtable object contains items represented by key/value pairs. Keys are used as indexes, and searching by key enables fast lookup of values.
Add items to a Hashtable using the Add() method.
The code below creates a Hashtable object named mycountries and adds four elements:
Data Binding
The Hashtable object can automatically generate text and values for the following controls:
- asp:RadioButtonList
- asp:CheckBoxList
- asp:DropDownList
- asp:Listbox
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
Demo Example »
**Note:** You cannot choose the sort order of items added to a Hashtable. To sort items alphabetically or numerically, use a SortedList object.