sorting Datatable using Dataview
Posted on 2008-06-10
I need to sort a datatable only once and then iterate through its rows multiple times (after postbacks, so I am using a cache to store the datatable).
DataTable dt = null;
DataView dv = ((DataTable)Cache[User.Identity.Name]).DefaultView;
dv.Sort = "date";
dt = dv.Table;
At this point, will the datatable 'dt' have sorted rows?
Another thing, does the following statement always return the rows of the datatable in the same order, if I use it multiple times?
foreach (DataRow dr in dt.Rows)
I would prefer not to use this:
foreach (DataRowView drv in dt.DefaultView).