3 回答
TA贡献1863条经验 获得超2个赞
您可以使用会话变量来存储最新的排序表达式,并在下次对网格进行排序时,将网格的排序表达式与存储最后一个排序表达式的Session变量进行比较。如果两列相等,则检查上一个排序的方向,然后按相反的方向排序。
例:
DataTable sourceTable = GridAttendence.DataSource as DataTable;
DataView view = new DataView(sourceTable);
string[] sortData = ViewState["sortExpression"].ToString().Trim().Split(' ');
if (e.SortExpression == sortData[0])
{
if (sortData[1] == "ASC")
{
view.Sort = e.SortExpression + " " + "DESC";
this.ViewState["sortExpression"] = e.SortExpression + " " + "DESC";
}
else
{
view.Sort = e.SortExpression + " " + "ASC";
this.ViewState["sortExpression"] = e.SortExpression + " " + "ASC";
}
}
else
{
view.Sort = e.SortExpression + " " + "ASC";
this.ViewState["sortExpression"] = e.SortExpression + " " + "ASC";
}
- 3 回答
- 0 关注
- 940 浏览
添加回答
举报