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).
6 comments:
Thank you!!! Saved me a few lines of code and a ton of frustration.
Brilliant! You saved my day!
It sure came in handy for me as well. Don't know how you figured out to use the text but I give you a 10 out of 10 for ingenuity!
Thank you very much, very helpful
Cheers! One of those simple things that could of taken hours to figure out! Thanks for sharing!
Thanks for posting this. I've been trying to DataBind a collection of custom class so that I could specify DataTextField and DataValueField.
So simple, and so perfect!
Post a Comment