1/12/2008

Dictionary as DropDownList Data Source

I have a Dictionary<T,T> called myListOptions. To use it as the datasource for an ASP.NET DropDownList called MyList...

MyList.DataSource = myListOptions;
MyList.DataTextField = "Value";
MyList.DataValueField = "Key";
MyList.DataBind();


It took me some rummaging to realize that you use the actual strings "Value" and "Key," so I hope this post comes in handy for someone else in the future (even if it's me).

Labels:

1 Comments:

Anonymous Anonymous said...

Thank you!!! Saved me a few lines of code and a ton of frustration.

5:41 PM  

Post a Comment

Links to this post:

Create a Link

<< Home