Adding Sorted Items to DropDownMenus at Runtime

I use drop down menus regularly. They are a very common control on most any website and often we are just getting a list of things out of a database and simply binding them to the drop down so the user can select one.

It’s very easy to bind items to an ASP.NET DropDownMenu. Removing items as well as adding items it just as easy. But what if you need to add items to the DropDownMenu when the list has already been DataBound and you need to ensure that all the items in the DropDown have been sorted (either by the Text or the Value)? This is a little bit tricky, which is why I’ve taken the time to show you how to do it (and so I can use this example next time I need it).



Leave a Reply

Your email address will not be published. Required fields are marked *

eight + eight =