Groups | Blog | Home
all groups > asp.net > march 2005 >

asp.net : Sorting a ListBox Control


Brock Allen
3/24/2005 7:54:47 PM
If your data is in an array, then this approach will work:

string[] data = new string[] {"zzz", "yyy", "bbb", "ccc", "aaa", "xxx"};
Array.Sort(data);

_dropDownList.DataSource = data;
_dropDownList.DataBind();

If your data is in a DataTable/DataSet:

DataSet ds = GetDataSetFromDatabase();
DataView dv = new DataView(ds.Tables["TheTable"]);
dv.Sort = "MyColumn";

_dropDownList.DataSouce = dv;
_dropDownList.DataBind();


-Brock
DevelopMentor
http://staff.develop.com/ballen



[quoted text, click to view]


Nathan Sokalski
3/24/2005 10:47:58 PM
I have a ListBox Control for which I would like to sort the ListItems. What
is the best way to do this? If possible, can someone show me a simple
example? Any help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

AddThis Social Bookmark Button