我需要根据从GridView中获取的列和排序方向,对一个内存中的DataTable进行排序。函数应该如下所示:
public static DataTable resort(DataTable dt, string colName, string direction)
{
DataTable dtOut = null;
....
}
我需要帮助填写这个函数。我认为可以使用Select语句,但不确定如何使用。由于浏览器的原因,我无法点击评论,但您可以向我展示就地或新的DataTable解决方案中的任何一个。对于向我提供指针的人,请提供一个类似于原型的编码函数。
怎么样:
// 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;
}
dt.DefaultView.ToTable();
。 - MattD