bind Dictionary to DropDownList

  • Thread starter Thread starter John Grandy
  • Start date Start date
J

John Grandy

Is it possible to bind a Dictionary to a DropDownList ?

The most obvious code fails :

Dictionary<string,string> dictionary = new Dictionary<string,string>

dictionary.Add("Name1","Value1");
//add some more items ...

DropDownList.DataSource = dictionary;
DropDownList.DataBind();

The dropdown displays items such as "[Name1,Value1]" , etc.
 
John,

Why not bind to the keys or values? This will give you single values
that you can bind to the list.
 
Back
Top