By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 697 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

numbers aren't sorting properly

P: n/a
Hi,
When you click on a column header to sort in ascending or descending order,
numbers (and dates) aren't sorted correctly. It turns up like this:

1
10
11
2
3
4
..
..
..

Is there a way to fix this?

Thanks,
Mel

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Gonna guess and say change the data type from a string to an int.

Please post more information...is this a web form, win form, are you talking
about a datagrid?

--

Derek Davis
dd******@gmail.com

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
Hi,
When you click on a column header to sort in ascending or descending
order,
numbers (and dates) aren't sorted correctly. It turns up like this:

1
10
11
2
3
4
.
.
.

Is there a way to fix this?

Thanks,
Mel

Nov 17 '05 #2

P: n/a
melanieab wrote:
Hi,
When you click on a column header to sort in ascending or descending order,
numbers (and dates) aren't sorted correctly. It turns up like this:

1
10
11
2
3
4
.
.
.

Is there a way to fix this?


They are sorting "properly" - just not usefully. Your sequence is equivalent
lexicographically to:
"1 "
"10"
"11"
"2 ", etc.

The problem is that you are NOT sorting numbers, you are sorting strings which
just happen to contain only the decimal digits "0" through "9". If this is a
listview you are restricted to strings, I believe. In that case you could
format them all to the same length by prepending leading zeroes as per, e.g.,
MyString = MyNum.ToString("000000000"), or else supply your own sort routine.
(Other types of controls may let you specify that your column contains integers,
in which case the built-in sort would handle them OK.)

Similarly, MyString = MyDate.ToString("yyyy-MM-dd HH:mm:ss") would format your
dates so that they would sort the same both as dates and as strings . . .

HTH,
-rick-
Nov 17 '05 #3

P: n/a
Thanks! This was the changing to the int thing (in a datagrid). Never even
occurred to me.

"carion1" wrote:
Gonna guess and say change the data type from a string to an int.

Please post more information...is this a web form, win form, are you talking
about a datagrid?

--

Derek Davis
dd******@gmail.com

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
Hi,
When you click on a column header to sort in ascending or descending
order,
numbers (and dates) aren't sorted correctly. It turns up like this:

1
10
11
2
3
4
.
.
.

Is there a way to fix this?

Thanks,
Mel


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.