in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

Cory Robinson's Blog

Sorting and Paging GridViews with Custom Object Collections

 

    protected void PendingWorkGridView_OnSorting(object sender, GridViewSortEventArgs e)

    {

        // For some reason the SortDirection property is not getting set automatically so set manually

        e.SortDirection = e.SortExpression.IndexOf(" DESC") > 0 ? SortDirection.Descending : SortDirection.Ascending;

 

        List<MyWorklistItem> pendingWorkItems = (List<MyWorklistItem>) Session["MyWorkItems"];

 

        pendingWorkItems.Sort(new MyWorklistItemComparer(e.SortBLOCKED EXPRESSION;

 

        // Update SortExpression for the column, toggling between ASC and DESC

        foreach (DataControlField column in PendingWorkGridView.Columns)

        {

            if (column.SortExpression == e.SortExpression)

            {

                column.SortExpression = e.SortDirection == SortDirection.Ascending

                                            ? e.SortExpression + " DESC"

                                            : e.SortExpression.Replace(" DESC", string.Empty);

 

                break;

            }

        }

 

        PendingWorkGridView.DataSource = pendingWorkItems;

        PendingWorkGridView.DataBind();

    }

 

    protected void PendingWorkGridView_OnPageIndexChanging(object sender, GridViewPageEventArgs e)

    {

        PendingWorkGridView.PageIndex = e.NewPageIndex;

        PendingWorkGridView.DataBind();

    }

Read the complete post at http://www.dotnetmafia.com/Home/tabid/37/EntryID/145/Default.aspx

2015 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems