I need to resort, in memory, a DataTable based on a column and direction that are coming from a GridView. The function needs to look like this:
public static DataTable resort(DataTable dt, string colName, string direction)
{
DataTable dtOut = null;
....
}
I need help filling in this function. I think I can use a Select statement but I am not sure how. I can't click on Comments because of this browser but you can show me an in-place or new DataTable solution, either one. For the people showing me pointers, please, I need a coded function similar to the one prototyped.
How about:
// ds.Tables[0].DefaultView.Sort="au_fname DESC";
public static void Resort(ref DataTable dt, string colName, string direction)
{
string sortExpression = string.Format("{0} {1}", colName, direction);
dt.DefaultView.Sort = sortExpression;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…