如何在Asp.net Gridview中对单个列进行排序 [英] How to Sort a single Column in Asp.net Gridview

查看:71
本文介绍了如何在Asp.net Gridview中对单个列进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Asp.net Gridview中对单个列进行排序

============================ ====================



亲爱的朋友们,



正在使用asp.net Gridview我在Gridview中有很多列。我只需要对Login time Column进行排序。当用户点击Gridview登录时间栏的标题时。



它应排序所有特定栏目



请给我一个好的解决方案。谢谢

How to Sort a single Column in Asp.net Gridview
================================================

Dear Frnds,

am working on asp.net Gridview I have a number of columns in Gridview. I need to sort only the Login time Column. when users Clicks on Header of Gridview Login time column.

it should sort that all particular column

Please give me good Solution. Thanks

推荐答案

这些链接可以帮助你

http://csharpdotnetfreak.blogspot.com/2012/06/sorting-gridview-columns-headers-aspnet.html [ ^ ]

http://stackoverflow.com/questions/702600/sorting-and-paging- with-gridview-asp-net [ ^ ]
These links may help you
http://csharpdotnetfreak.blogspot.com/2012/06/sorting-gridview-columns-headers-aspnet.html[^]
http://stackoverflow.com/questions/702600/sorting-and-paging-with-gridview-asp-net[^]


hi,



试试这个





try this

 <asp:gridview xmlns:asp="#unknown">
              ID="grdCause"
              runat="server
              EnableSortingAndPagingCallback="True"
              AllowPaging="True"
              AllowSorting="True"
              onpageindexchanging="grdCause_PageIndexChanging"
              onsorting="grdCause_Sorting"
         >
</asp:gridview>





以下方法用于加载Gridview。在此方法中,我将采用数据集并将该数据集绑定到Gridview。 br />
ExecuteProcedure是我的sqlhelper类中的方法。对于该方法,请单击此处。



The following method is for Loading the Gridview .In this method am taking dataset and bind that dataset to Gridview.
ExecuteProcedure is the method in my sqlhelper class.For that method Click here.

private void LoadGrid()
    {
       
        DataSet ds = dal.ExecuteProcudere("CauseSelectAll", ht);
        grdCause.DataSource = ds.Tables[0];
        grdCause.DataBind();
    }

Gridview pageindexChanging Event  for paging:
protected void grdCause_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdCause.PageIndex = e.NewPageIndex;
        LoadGrid();
    }





用于排序的Gridview排序事件:





Gridview Sorting Event for Sorting:

protected void grdCause_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);
       }


   }



使用以下方法进行排序:


Use the following method for Sorting:

private void SortGridView(string sortExpression, string direction)
    {
        //  You can cache the DataTable for improving performance
        LoadGrid();
        DataTable dt = grdCause.DataSource as DataTable;
        DataView dv = new DataView(dt);
        dv.Sort = sortExpression + direction;

        grdCause.DataSource = dv;
        grdCause.DataBind();

    }
    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;
 }
    }


hiii,



类似的帖子在这里

http://codesnippts.blogspot.in/ 2010/02 / introduction-paging-and-sorting-are.html





http://gchandra.wordpress.com/2007/09/25/gridview-sortingpaging- wo-a-datasourcecontrol-datasource-vbnet / [ ^ ]
hiii,

similar thread is here
http://codesnippts.blogspot.in/2010/02/introduction-paging-and-sorting-are.html


http://gchandra.wordpress.com/2007/09/25/gridview-sortingpaging-wo-a-datasourcecontrol-datasource-vbnet/[^]


这篇关于如何在Asp.net Gridview中对单个列进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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