Sorting a ListBox Control

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Mar 25, 2005.

  1. 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

    http://www.nathansokalski.com/
    Nathan Sokalski, Mar 25, 2005
    #1
    1. Advertising

  2. Nathan Sokalski

    Brock Allen Guest

    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



    > 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.
    >
    Brock Allen, Mar 25, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. blenderdude
    Replies:
    0
    Views:
    969
    blenderdude
    Aug 3, 2003
  2. DC Gringo
    Replies:
    0
    Views:
    397
    DC Gringo
    Apr 6, 2004
  3. kent
    Replies:
    1
    Views:
    873
    Andrew de la Harpe
    May 3, 2004
  4. Simon Prince
    Replies:
    2
    Views:
    3,320
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
    Oct 19, 2004
  5. Nathan Sokalski

    Sorting a ListBox Control

    Nathan Sokalski, Mar 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,160
    Brock Allen
    Mar 25, 2005
Loading...

Share This Page