排序不能在整个gridview分页中实现? [英] Sorting not implement in whole gridview paging?

查看:109
本文介绍了排序不能在整个gridview分页中实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个Gridview控件,可以在其中应用分页和排序.但是当我单击gridview的任何列时,它仅对第一页记录而不是第二页记录进行排序.我想对分页中可用的所有记录进行排序.

谢谢,
Mangesh:-)

Hi,

I have a Gridview control where i apply Paging and sorting. But when i click any column of gridview it sort only first page record not second page record.i want to sort all records available in paging.

Thanks,
Mangesh :-)

推荐答案

Mangesh,

试试这个:
Hi mangesh,

Try this one:
private const string ASCENDING = " ASC";
private const string DESCENDING = " DESC";

public SortDirection GridViewSortDirection
{
    get
    {
        if (ViewState["sortDirection"] == null)
            ViewState["sortDirection"] = SortDirection.Ascending;

        return (SortDirection) ViewState["sortDirection"];                
    }
    set { ViewState["sortDirection"] = value; } 
}

protected void GridView_Sorting(object sender, GridViewSortEventArgs e)
{
    string sortExpression = e.SortExpression;

    if (GridViewSortDirection == SortDirection.Ascending)
    {
        GridViewSortDirection = SortDirection.Descending;
        SortGridView(sortExpression, DESCENDING);
    }
    else
    {
        GridViewSortDirection = SortDirection.Ascending;
        SortGridView(sortExpression, ASCENDING); 
    }   

}

private void SortGridView(string sortExpression,string direction)
{
    //  You can cache the DataTable for improving performance
    DataTable dt = GetData().Tables[0]; 

    DataView dv = new DataView(dt); 
    dv.Sort = sortExpression + direction;         

    GridView1.DataSource = dv;
    GridView1.DataBind();         
}



问候,
爱德华



Regards,
Eduard


这篇关于排序不能在整个gridview分页中实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆