469,341 Members | 6,935 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,341 developers. It's quick & easy.

How do I sort a dataview on a column that contains integers?

Hello, using c# I'm trying to sort a dataview on a column that contains integers. Apparently the option dvTempt.Sort = sFieldName; only sort as strings(or ASCII)...ex
5, 10, 11, 12, 101, 22, 24 is sorting 10, 101, 12, 22, 24, 5 when it should be sorting 5, 10, 11, 22, 24, 101. Could somebody help me with this?.
Oct 15 '09 #1
6 4900
Plater
7,872 Expert 4TB
If the underlying datatype is an integer, it should have sorted them as integers.
I think there is a way to specify a specical custom sort function right?
Oct 15 '09 #2
here is the code I'm using:

string sFieldName = "iWord";
dvTempt.Sort = sFieldName;

whrere iWord is a column in the dataview and contains numbers(int). But it is not sorting properly, it looks like it is considering the content of the column as ASCII or strings. The order in the column before the sort is as follow:
18, 22, 10, 24, 101, 5...after the sort: 10, 101, 18, 22, 24, 5...when it should be
5, 10, 18, 22, 24, 101
Oct 15 '09 #3
Plater
7,872 Expert 4TB
Right, but what is the datatype of column "iWord"? is it a string or an Int or?
Oct 19 '09 #4
Hello Plater, the datatype of the column "iWord" is an integer but the sort is sorting like if was a string and it is not sorting properly. This column is in a dataset and I'm using it in a dataview to do the sort.
Oct 19 '09 #5
Plater
7,872 Expert 4TB
So dvTempt.Columns["iWord"].ValueType reports "int" ?
Oct 19 '09 #6
Hi JLORA3659,

I think your DataTable column property set to

DataTable dt = new DataTable("MyDataTable");
dt.Columns.Add(new DataColumn("iWord", typeof(string)));

Use like below

DataTable dt = new DataTable("MyDataTable");
dt.Columns.Add(new DataColumn("iWord", typeof(int32)));

you will get. Thx.
Oct 21 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Denzil | last post: by
9 posts views Thread by Raymond Lewallen | last post: by
7 posts views Thread by DC Gringo | last post: by
3 posts views Thread by Peter Proost | last post: by
3 posts views Thread by gilly3 | last post: by
4 posts views Thread by G .Net | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.