Results 1 to 5 of 5

Thread: [RESOLVED] sorting drop down list

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Resolved [RESOLVED] sorting drop down list

    I am retrieving values from xml and put it to the drop down list control. But it's out of order, how can I sort them?

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: sorting drop down list

    Are you using DataSet/DataTable to read data from XML? If so, you can call the Sort() method of its DefaultView and set the order name.

    E.g., Assuming you are using DataTable
    C# Code:
    1. //DataTable dt = reading data from xml
    2.  
    3. dt.DefaultView.Sort = "<columnname> <ASC/DESC>";
    Show Appreciation. Rate Posts.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: sorting drop down list

    Quote Originally Posted by Harsh Gupta
    you can call the Sort() method of its DefaultView
    Sort is a property, not a method, which is why you're assigning a value to it rather than calling it.

    If you're not using a DataTable then arrays and the generic List class also have Sort members, and these ones are methods.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: sorting drop down list

    My bad. Yes it is a property. Can't even say that was a typo!!!
    Show Appreciation. Rate Posts.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: sorting drop down list

    Get your XmlNodeList, put it in a List<yourtype> and then sort it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width