ASP.NET framework does not have a sort method on the dropdown list as you
probably noticed. You have two options and they are about equally.
1) sort the list before you do your databind().
2) create a class that inherits from DropDownList and supply your own
method. You would probably want to do something like...
using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections;
namespace JoesExample
{
public class MyDropDownList : System.Web.UI.WebControls.DropDownList
{
public void Sort()
{
ListItemCollection lic = base.Items;
ArrayList al = new ArrayList(lic);
al.Sort(new MyComparer());
lic.Clear();
lic.AddRange( (ListItem[])al.ToArray(typeof(ListItem)) );
}
private class MyComparer : System.Collections.IComparer
{
public int Compare(object x, object y)
{
return new CaseInsensitiveComparer().Compare( ((ListItem)x).Text,
((ListItem)y).Text );
}
}
}
}
Joe
MCAD
SRE (Simple Rule Engine)
https://sourceforge.net/projects/sdsre/