Sorting in dataview not happening properly(C#3.0)
Posted
by Newbie
on Stack Overflow
See other posts from Stack Overflow
or by Newbie
Published on 2010-06-15T12:15:01Z
Indexed on
2010/06/15
12:32 UTC
Read the original article
Hit count: 265
c#3.0
I have the following
DataTable dt = new DataTable();
dt.Columns.Add("col1", typeof(string));
dt.Columns.Add("col2", typeof(string));
dt.Rows.Add("1", "r1");
dt.Rows.Add("1", "r2");
dt.Rows.Add("1", "r3");
dt.Rows.Add("1", "r4");
dt.Rows.Add("2", "r1");
dt.Rows.Add("2", "r2");
dt.Rows.Add("2", "r3");
dt.Rows.Add("2", "r4");
dt.Rows.Add("3", "r1");
dt.Rows.Add("3", "r2");
dt.Rows.Add("3", "r3");
dt.Rows.Add("3", "r4");
dt.Rows.Add("1", "r1");
dt.Rows.Add("1", "r2");
DataView dv = new DataView(dt);
dv.Sort = "col1";
DataTable dResult = dv.Table;
I am trying to sort the datatable with the help of dataview so that the result will be
1 r1
1 r2
...
2 r1
2 r2
...
3 r1
3 r2
......
Means all 1's first followed by 2's and 3r's
Even I tried with dt.DefaultView.Sort = "col1";
but no luck.
But it is not happening. Only the result i am able to view in dv.Sort
and not the datatable (dResult)
I am using C#3.0.
Please help
Thanks
© Stack Overflow or respective owner