Home > DeveloperSection > Forums > Bind List<Dictionary<string,string>> to DropDownList
john rob

Total Post:108

Points:756
Posted on    September-02-2014 12:32 AM

 ASP.Net
Ratings:


 1 Reply(s)
 1159  View(s)
Rate this:

var dict = new Dictionary<string,string>();

dict.Add("A","123");

dict.Add("B","456");

dict.Add("C","789");

dict.Add("D","000");

var list = new List<Dictionary<string,string>>(); //pretty much like a DataTable

list.Add(dict); //more than one dict in the list

//ddl is a dropdownlist

ddl.DataSource = list

ddl.DataTextField ="[A]";

ddl.DataValueField ="[C]";

ddl.DataBind();



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-02-2014 12:48 AM

Hi John, 

You should bind your dictionary, not list. Something like this :

var dict = new Dictionary<string,string>();

dict.Add("A","123");

ddl.DataSource = dict

ddl.DataTextField ="Key";

ddl.DataValueField ="Value";

ddl.DataBind();


Don't want to miss updates? Please click the below button!

Follow MindStick