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

DataView - Integer Sorting

P: n/a
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 ***
Dec 11 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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 ***
Dec 11 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.