DataView - Integer Sorting  
Author Message
topnotchthrillr





PostPosted: Mon Dec 10 23:32:00 PST 2007 Top

Visual C#.Net >> DataView - Integer Sorting Hi All,

I have used gridview in my application and i m using dataview to sort
the grid. But when i sort the numeric column, dataview sorts it like a
string.

So, after sorting, instead of getting 1,3,11.... i get 1,11,3... in asc
and 3,1,11 in dec..

Anybody has idea regarding this???

Regards,
Mansi Shah.

*** Sent via Developersdex http://www.developersdex.com ***

DotNet201  
 
 
MortenWennevik





PostPosted: Mon Dec 10 23:32:00 PST 2007 Top

Visual C#.Net >> DataView - Integer Sorting Hi,

I'm afraid I can't reproduce your problem. Given that the numeric column is
of a numeric type, the dataview sorts it correctly and I get 1, 3, 11 as
expected.

DataTable dt = new DataTable();
dt.Columns.Add("Strings", typeof(string));
dt.Columns.Add("Numbers", typeof(Int32));

DataRow dr = dt.NewRow();
dr["Strings"] = "One";
dr["Numbers"] = 1;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Strings"] = "Eleven";
dr["Numbers"] = 11;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["Strings"] = "Three";
dr["Numbers"] = 3;
dt.Rows.Add(dr);

DataView dv = new DataView(dt);
dv.Sort = "Numbers ASC";
grid.DataSource = dv;

--
Happy Coding!
Morten Wennevik [C# MVP]


"Mansi Shah" wrote:

> Hi All,
>
> I have used gridview in my application and i m using dataview to sort
> the grid. But when i sort the numeric column, dataview sorts it like a
> string.
>
> So, after sorting, instead of getting 1,3,11.... i get 1,11,3... in asc
> and 3,1,11 in dec..
>
> Anybody has idea regarding this???
>
> Regards,
> Mansi Shah.
>
> *** Sent via Developersdex http://www.developersdex.com ***
>