Thursday, May 14, 2009

Bind HashTable Data with Dropdownlist.

We can bind hashtanle with asp.net 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 asp.net..

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";
ddl1.DataBind();
form1.Controls.Add(ddl1);


Thanks.