Thursday, May 14, 2009

Bind HashTable Data with Dropdownlist.

We can bind hashtanle with dropdownlist same way as datatable and dataset.
you have to remember that how to set DataTextField and DataValueFiled Properties
of dropdownlist.

this is the code to bind HashTable with dropdownlist in

DropDownList ddl1 = new DropDownList();
System.Collections.Hashtable hsTable = new Hashtable();
hsTable.Add("0", "India");
hsTable.Add("1", "USA");
ddl1.DataSource = hsTable;
ddl1.DataTextField = "Value";
ddl1.DataValueField = "Key";