Expression Evaluation Time: ms / Round trip: ms
Custom Paging Control
22. Mar
2013
by Dario Category:
Technical
2

This short blog post shows you how to implement your custom paging control to use with the Composite Web Part.

There is a PageInfo object that you can access when you have enabled paging (PageSize > 0) in the Composite Web Part.

Instead of using the default paging control with <PagingControl/> you can define an expression variable that renders your custom HTML.

public string GetPagingHtml()
{
    IPageInfo pi = (IPageInfo)Expr("PageInfo");

    if (pi.HasMorePages)
    {
        return String.Format("Page {0} - <a href='#' Event='PageLink' StartIndex='{1}'>Next</a>",
            pi.StartIndex / pi.PageSize + 1, pi.StartIndex + pi.PageSize);
    }
    else
    {
        return String.Format("Page {0} - No more pages.", pi.StartIndex / pi.PageSize + 1);
    }
} 

In the FooterTemplate then use {Acme.Paging.GetPagingHtml()} instead of <PagingControl/>.

IPageInfo provides all required information such as StartIndex, RowCount, PageSize etc.

The Composite Web Part does the event binding after each AJAX callback that occurs in event of paging. Therefore you have to add an Event='PageLink' attribute to all the HTML elements that represents a link to page back, forward or jump to a specific page. Further the element needs an attribute StartIndex with the index of the first row of that page.

Comments
TankT72
10.09.2013 01:30
As I understand, this code should be in a Composite User control? I created one - Test.Paging.xml. Pasted the code and used it in the FooterTemplate of the Composite Web Part like this - Test.Paging.GetPagingHtml but I receive an null reference exception. pi is null. I have Pagging enabled and set to 2. What is wrong?
TankT72
11.09.2013 08:40
Ok the problem was with the issue, when number of items is less or equal to a page size. I think this is quite important thing and should be described here.
ABOUT

This blog is about technical and non-technical aspects of the product MatchPoint and other SharePoint topics.

If you would like to post an article or if you have an idea for a post, please contact us.

ARCHIVE
June 2014 (3)
May 2014 (1)
1-5 (23) 
COMMENTS
sothrieg
23.04.2014 02:10
Danke Matthias, funktioniert perfekt! | Goto Post
Matthias Weibel
23.04.2014 09:59
In the configuration of a MatchPoint Web Part you ... | Goto Post
sothrieg
22.04.2014 12:52
Can you pls make an example for the following new ... | Goto Post
baehleta
06.12.2013 10:07
This is great, thank you!
Unfortunatley, the resto... | Goto Post
Thomas.Stoller
26.09.2013 02:11
Problem solved: typo! | Goto Post