private void Mdb_Dealer_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if(ViewState["sortField"]!=null && ViewState["sortField"].ToString().IndexOf(e.SortExpression)==0)
{
if(ViewState["sortField"].ToString().IndexOf("desc")>0)
ViewState["sortField"] = ViewState["sortField"].ToString().Replace("desc","asc");
else
ViewState["sortField"] = ViewState["sortField"].ToString().Replace("asc","desc");
}
else
ViewState["sortField"] = e.SortExpression + " asc ";
调用DataGrid绑定事件;
}
在DataGrid的绑定事件里写SQL语句时要注意在最后进行判断ViewState["sortField"] 是否是空!如果不为空就要进行order by排序!