?
Solved

Sorting a DataTable

Posted on 2008-11-18
4
Medium Priority
?
405 Views
Last Modified: 2012-05-05
Hello,

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?

Thanks
0
Comment
Question by:Relegence
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:amx
ID: 22983850
if the number is is less than 10 then prefix it with a zero

Example:
task4 becomes task04

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

Author Comment

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

Accepted Solution

by:
amx earned 1200 total points
ID: 22984081
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:

http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=318609&SiteID=1

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

Author Comment

by:Relegence
ID: 22984164
Thank you so much!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

839 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