|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Display items from dropdown list in alphabetical orderHi,
Is there any way where I can display items from dropdown list in alphabetical order? Thanks. 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/ Show quoteHide quote "Siew Yee" <Siew***@discussions.microsoft.com> wrote in message news:64C96226-0DE1-425C-B954-4D96BDC356A9@microsoft.com... > Hi, > > Is there any way where I can display items from dropdown list in > alphabetical order? > Thanks. > >
CompareValidator Only Works On Manual Input
Base Page Design Question Which page load fires first? ASPX or ASCX? PropertyDescriptor in GetDataSource Render TreeViewControls in .net 2003 Repeater question Resolving datasource expression Resolving datasource expression 2.0 ascx on a 1.1 aspx? Bizarre - DataGrid inside HTML Table |
|||||||||||||||||||||||