Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Paging - Rows in first page also showing in second page: listitemcollectionposition

$
0
0

Hi,

I am trying to use the listitemcollectionposition to achieve paging. The pagination is shown, but some of the records in first page are getting displayed in second page as well.

I have totally 13 records in the list, and paging is applied for 10 items to show. I have set the rowcount to 10.

   private void FillData(string pagingInfo)
        {
            int currentPage = Convert.ToInt32(ViewState["CurrentPage"]);

uint rowCount = 10; // Default of 10 items per page

string columnValue = string.Empty;

string nextPageString = "Paged=TRUE&p_ID={0}&p_";

string PreviousPageString = "Paged=TRUE&PagedPrev=TRUE&p_ID={0}&p_";

SPListItemCollection collection;
collection = GetTestItems(pagingInfo, rowCount);
}

public SPListItemCollection GetTestItems(string pagingInfo, uint rowLimit)
{
  using (SPSite oSite = new SPSite(Sitename))
 {
  using (SPWeb oWeb = oSite.OpenWeb())
  {
   SPList lstPages = oWeb.Lists["Pages"];
 SPQuery sQuery = new SPQuery();
 SPListItemCollection collection;
sQuery.RowLimit = rowLimit;
sQuery.Query = "<Where>" +"<And>" +"<And>" +"<Contains><FieldRef Name='PublishingPageLayout'/><Value Type='URL'>TC_NtestPageLayout.aspx</Value></Contains>" +"<Eq><FieldRef Name='_ModerationStatus'/><Value Type='ModStat'>0</Value></Eq>" +"</And>" +"<Eq><FieldRef Name='_Level'/><Value Type='Integer'>1</Value></Eq>" +"</And>" +"</Where><OrderBy><FieldRef Name='TestLayoutDate' Ascending='FALSE' /></OrderBy>";

sQuery.ViewFields = string.Concat(
  "<FieldRef Name='PublishingPageLayout' />","<FieldRef Name='Title' />","<FieldRef Name='EncodedAbsUrl' />","<FieldRef Name='TestLayoutDate' />");

sQuery.ViewFieldsOnly = true;

if (!string.IsNullOrEmpty(pagingInfo))
{
SPListItemCollectionPosition position = new SPListItemCollectionPosition(pagingInfo);

sQuery.ListItemCollectionPosition = position;
}

collection = lstPages.GetItems(sQuery);

return collection;
}
 }
 }

How to get the Paging properly?

Thanks


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>