DataView - Integer Sorting

  • Thread starter Thread starter Mansi Shah
  • Start date Start date
M

Mansi Shah

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.
 
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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top