【发布时间】:2011-02-15 15:31:23
【问题描述】:
我需要在内存中使用基于来自 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;
}
【问题讨论】: