First of all, keep in mind that sorting the items will change each item's index. Make sure this won't cause any problems in your code.
The most straight-forward approach is to copy the items to an array, sort them, clear the original item list, and copy the sorted items back into the drop down list's items collection.
object[] SortedItems = new object[ddlMyList.Items.Count];
for (int i = 0; i < SortedItems.Length; i++)
{
SortedItems[i] = cbTest.Items[i];
}
Array.Sort(SortedItems);
ddlMyList.Items.Clear();
ddlMyList.Items.AddRange(SortedItems);
--
Kai Brinkmann [MSFT]
Please do not send e-mail directly to this alias. This alias is for newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Morten" <mo**************@hotmail.com> wrote in message news:Ox****************@TK2MSFTNGP11.phx.gbl...
Hi!
I've created a webform with a dropdown to which I've added some static
items. I'm adding some extra items in my code. I'd like to sort the items
after I've finished adding my new items. Can someone provide an example of
how to do this?
Thanks in advance for your help.
Morten