ASP.NET Web Forms - Hashtable Object
The Hashtable object contains items represented as key/value pairs.
Try It - Examples
Creating a Hashtable
The Hashtable object contains items represented as key/value pairs. The key is used as an index, allowing for fast searches of values by searching for the key.
Items are added to the Hashtable using the Add() method.
The following code 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 to create the list and bind the values in the list to the RadioButtonList control:
Next, add a subroutine that will be executed when the user clicks an item in the RadioButtonList control. When a radio button is clicked, a line of text will appear in the label:
Example
Note: You cannot choose the order of items added to the Hashtable. For alphabetical or numerical sorting of items, use the SortedList object.