bind Dictionary to DropDownList

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.
 
N

Nicholas Paldino [.NET/C# MVP]

John,

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top