public static DataTable resort(DataTable dt, string colName, string direction)
{
DataTable dtOut = null;
dt.DefaultView.Sort = colName + " " + direction;
dtOut = dt.DefaultView.ToTable();
return dtOut;
}
controlsConfig = resort(controlsConfig, "FieldGroup", "ASC");
public static DataTable Sortbyint(DataTable tdt, string colName, string direction)
{
DataTable Ndt = new DataTable();
DataTable dt = tdt; // Assume this method returns the datatable from service
DataTable dt2 = dt.Clone();
dt2.Columns["SortOrder"].DataType = Type.GetType("System.Int32");
foreach (DataRow dr in dt.Rows)
{
dt2.ImportRow(dr);
}
dt2.AcceptChanges();
DataView dv = dt2.DefaultView;
dv.Sort = "SortOrder ASC";
Ndt = dv.ToTable();
return Ndt;
}
controlsConfig = Sortbyint(controlsConfig, "SortOrder", "ASC");
No comments:
Post a Comment