Sorting a DataTable

Posted on 2008-11-18
Last Modified: 2012-05-05

I am using a DataTable within a C# ASP.NET application.
It has a 'Name' column which is sortable.
The problem is that when sorting the value 'test12', for example, is placed before 'test4'.
How can I fix that?

Question by:Relegence
    LVL 9

    Expert Comment

    if the number is is less than 10 then prefix it with a zero

    task4 becomes task04

    you just need to update the sql to do this for you

    Author Comment

    I am afraid I can't do that. The user can enter any string he wishes.
    'test4' and 'test12' where just examples
    LVL 9

    Accepted Solution

    there is no easy way of doing this but i can point you in the right direction.

    the sorting you're describing is called a Natural Sort Order.

    I've had a look around and there are lots of examples but they all involve alot of extra coding. The best and simpliest example i could find was here:

    Its the 3rd post from the bottom you should read as it has a good example.

    Author Comment

    Thank you so much!

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now