I have a document library. I am displaying this library using my own CSS in a custom web part. My question is how do I apply pagination?
Normally in ASP.Net we simply use

SQL query such as SELECT  *
FROM     sys.databases
ORDER BY name 

to limit the numeber of rows returned based on current page. Is there such a thing in SharePoint when fetching data from list/library?


For this, you'll want to use the ListItemCollectionPosition property of SPQuery.

SPListItemCollectionPosition is the class which helps to achieve paging and sorting the results fetched by SPQuery.

See here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitemcollectionposition.aspx

and here for a more comprehensive example


Paging using CAML cannot go to a Nth page directly, like you can do in SQL.

For using paging, you need to use ListItemCollectionPosition property in the SPQuery.


  • Limit the Columns (ViewFields) of your query
  • Set the RowLimit on the SPQuery
  • Don't forget to explicit the OrderBy in the Query
  • Choose an indexed column (if possible) to OrderBy
  • Every time you run the query, this property will return the string for the next page, so you pass this on the next query to get the next page.
  • I had some issues using PagePrev in my project, even though the CAML was correct, so I've implemented a solution to store the pages in ViewState, then I can go to the next/prev page using "Page Index" (custom property of the Webpart)

If you have further questions, please comment. If not, please accept the answer

EDIT1) References - http://www.c-sharpcorner.com/UploadFile/40e97e/sharepoint-2010-using-splistitemcollectionposition-for-fas/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.