GridView排序记录,记录给自己
1.页面文件的设置就不说了.
2.数据绑定时
3.Sorting事件代码2.数据绑定时
protected void BindGrid()
{
string sortexpression=GridView1.Attributes["SortExpression"];
string sortdirection=GridView1.Attributes["SortDirection"];
DataTable dt = employer.BindResumeList();
if (!string.IsNullOrEmpty(sortdirection) && !string.IsNullOrEmpty(sortexpression))
{
dt.DefaultView.Sort = string.Format("{0} {1}",sortexpression,sortdirection);
}
this.GridView1.DataSource = dt.DefaultView;
this.GridView1.DataBind();
}
{
string sortexpression=GridView1.Attributes["SortExpression"];
string sortdirection=GridView1.Attributes["SortDirection"];
DataTable dt = employer.BindResumeList();
if (!string.IsNullOrEmpty(sortdirection) && !string.IsNullOrEmpty(sortexpression))
{
dt.DefaultView.Sort = string.Format("{0} {1}",sortexpression,sortdirection);
}
this.GridView1.DataSource = dt.DefaultView;
this.GridView1.DataBind();
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
string sortexpression = e.SortExpression.ToString();
string sortdirection = "ASC";
if (sortexpression == GridView1.Attributes["SortExpression"])
{
sortdirection=(GridView1.Attributes["SortDirection"]==sortdirection?"DESC":"ASC");
}
GridView1.Attributes["SortExpression"] = sortexpression;
GridView1.Attributes["SortDirection"] = sortdirection;
BindGrid();
}
{
string sortexpression = e.SortExpression.ToString();
string sortdirection = "ASC";
if (sortexpression == GridView1.Attributes["SortExpression"])
{
sortdirection=(GridView1.Attributes["SortDirection"]==sortdirection?"DESC":"ASC");
}
GridView1.Attributes["SortExpression"] = sortexpression;
GridView1.Attributes["SortDirection"] = sortdirection;
BindGrid();
}