in

Dot Net Mafia

Group site for developer blogs dealing with (usually) Ionic, .NET, SharePoint, Office 365, Mobile Development, 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

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