GridView排序记录,记录给自己

1.页面文件的设置就不说了.
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();
    }
3.Sorting事件代码
    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();
    }
posted @ 2009-09-12 11:40  ForFreeDom  阅读(271)  评论(0编辑  收藏  举报