Wednesday, February 16, 2011

HashTable in ASP.Net Fill Data in Dropdownlist Using HashTable

Hashtable hs = new Hashtable();
hs.Add("1","Ram Singh");
hs.Add("2", "Ram Singh");
hs.Add("3", "Ram Singh");
hs.Add("4", "Ram Singh");
hs.Add("5", "Ram Singh");
hs.Add("6", "Ram Singh");
hs.Add("7", "Ram Singh");
hs.Add("8", "Ram Singh");
DropDownList1.DataSource = hs;
DropDownList1.DataValueField = "Key";
DropDownList1.DataTextField = "value";
DropDownList1.DataBind();

HashSet theSet1 = new HashSet();
theSet1.Add(1);
theSet1.Add(2);
theSet1.Add(2);
theSet1.Add(1);
theSet1.Add(2);
theSet1.Add(2);
// theSet1 contains 1,2

HashSet theSet2 = new HashSet();
theSet2.Add(1);
theSet2.Add(3);
theSet2.Add(4);
// theSet2 contains 1,3,4

theSet1.UnionWith(theSet2);
DropDownList2.DataSource = theSet1;
//DropDownList1.DataValueField = "Key";
//DropDownList1.DataTextField = "value";
DropDownList2.DataBind();

//Response.Write();

No comments:

Post a Comment