protected void GridView_Sorting(object sender, GridViewSortEventArgs e)
{
string sPage = e.SortExpression;
if(ViewState["SortOrder"].ToString()== sPage)
{
if(ViewState["OrderDire"].ToString()== "Desc")
ViewState["OrderDire"] = "ASC";
else
ViewState["OrderDire"] = "Desc";
}
else
{
ViewState["SortOrder"] =e.SortExpression;
}
dv = new DataView();
dv = dt.DefaultView;
string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"];
dv.Sort = sort;
GridView.DataSource = dv;
GridView.DataBind();
}
网上找了半天,发现其实是用了dataview视图的sort属性。
结合ViewState["SortOrder"]和ViewState["OrderDire"]
搞定问题后的感觉杠杠的。