CRM 2011 Customer Portal: Adding Paging and Sorting to Caseview

A Customer Portal is only as good as it is User/Customer Friendly.  One of the things that I have been asked is… Can you add sorting and paging to the case view?  No matter how you sort the result set some one will want it sorted differently.  The most user-friendly way to present a list is to allow on sorting by the user.

You will need to make changes to the viewcases.aspx page as well as the code behind for that page.

you will need to add the reference to the

using System.Data;

Then you need to add these three sorting and paging functions.  For the caseview you should be able to straight copy and past.  If you are using this for another view you will need to update CaseList to the name of your gridview and change the names of the functions in the next code chunk.


protected void CaseList_PageIndexChanging(object sender, GridViewPageEventArgs e)
 {
 CaseList.PageIndex = e.NewPageIndex; CaseList.DataBind();
 }
 protected void CaseList_Sorting(object sender, GridViewSortEventArgs e)
 {
 DataTable dtSortTable = CaseList.DataSource as DataTable;
 if (dtSortTable != null)
 { DataView dvSortedView = new DataView(dtSortTable);
 dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);
 CaseList.DataSource = dvSortedView; CaseList.DataBind();
 }
 }
 private string getSortDirectionString(SortDirection sortDirection)
 {
 string sortExpression = ViewState["SortExpression"] as string;
 newSortDirection = "ASC";
 string lastDirection = ViewState["SortDirection"] as string;
 if ((lastDirection != null) && (lastDirection == "ASC"))
 {
 newSortDirection = "DESC";
 }
 ViewState["SortDirection"] = newSortDirection;
 return newSortDirection;
 }

The gridview tag on the aspx page should look like this.  The red is what needs to be added.

<asp:<span class="hiddenSpellError">GridView ID="CaseList" runat="server" CssClass="cases" <span style="color: #ff0000;">OnPageIndexChanging="CaseList_PageIndexChanging"</span><span style="color: #ff0000;"> OnSorting="CaseList_Sorting" AllowPaging="true" AllowSorting="true"</span>
 OnRowDataBound="CaseList_OnRowDataBound" >
 </asp:GridView>

Now your page should have headers links and pagination like this

This same code can be used where ever you need to add sorting and paging with a gridview.

About dorothyjarry

Super Dots
This entry was posted in CRM 2011, Customer Portal, Dynamics. Bookmark the permalink.

4 Responses to CRM 2011 Customer Portal: Adding Paging and Sorting to Caseview

  1. Jeremy says:

    After a minor modification, this worked like a charm. newSortDirection needs to be initialized as a string. Just adding String before we first set the default sort order handles this just fine.

    It also supports the view filtering and the best part is, the default sort method I set previously as well also worked. That was set in the CaseAccess.cs in GetCasesByCustomer by specifying a orderby in my findCases queries
    orderby c.GetAttributeValue(“createdon”) descending

    Thanks for the code. That makes it a interactive Customer Portal and thus more useful for customers.

    Like

  2. Why viewers still use to read news papers when in this technological world the whole thing
    is available on net?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s