I have dropdown list as follow:
<select id="DropdownID">
<option value="1">Ccc</option>
<option value="2">Aaa</option>
<option value="3">Bbb</option>
</select>
but i want dropdown elements sorted by text not value, in alphabetical order:
<select id="DropdownID">
<option value="2">Aaa</option>
<option value="3">Bbb</option>
<option value="1">Ccc</option>
</select>
I fill it on this way:
Dictionary<int, string> myDataDictionary = new Dictionary<int, string>();
// (...)
DropdownID.DataSource = myDataDictionary;
DropdownID.DataTextField = "value";
DropdownID.DataValueField = "key";
DropdownID.DataBind();
Even if values in dictionary are sorted correctly, in dropdown they are always ordered by value.
How to sort items in dropdow by text rather than by value ?
Hi there I have this working sample, what ever I do with the dictionary the drop down is ordered correctly.
could you post your working sample so we could reproduce your error plz.
Edit: 13:21 22/09/2009
What ever order you put your data in is the order that the dropdown list will use to display the collection. I think there must be something else that you are not aware off. The best way to find out if it is a problem with your code or something is truly amiss is to write a test app get something simple from scratch try to reproduce the behaviour of the original app.