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

Help with SPQuery - Not returning records

$
0
0

Hi,

I am trying to query the Pages library for a particular page layout and which is Published.

I have a custom field "Date", which is added when a page is created with custom page layout.

I have the below dates for each of the pages:

page 3 - 6/26/2014
page 13- 6/13/2014
page 12- 6/12/2014
page 6- 6/12/2014
page 11- 6/11/2014
page 4- 6/11/2014
page 1- 6/10/2014
page 10- 6/10/2014
page 9- 6/9/2014
page 8- 6/7/2014
page 7- 5/6/2014
page 2- 4/30/2014
page 5- 2/28/2014

I am trying to show this in a visual webpart, in the above order. Row limit is set as 10.

I have used the below code to show the data in a Gridview. The first 10 records are getting shown, but the next 3 records are never shown (page7,page2,page5) , but a mix of first data records is getting shown.

SPList lstPages = oWeb.Lists["Pages"];
SPQuery sQuery = new SPQuery();
SPListItemCollection collection;
sQuery.RowLimit = 10;
sQuery.Query = "<Where>" +"<And>" +"<And>" +"<Contains><FieldRef Name='PublishingPageLayout'/><Value Type='URL'>Test_PageLayout.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>";

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

sQuery.ListItemCollectionPosition = position;
}

collection = lstPages.GetItems(sQuery);

I have followed the article: http://ajamaeen.blogspot.in/2013/02/paging-with-splistitemcollectionposition.html

Sort is based on the custom "Date" field descending.

What am I missing?

Thanks


Viewing all articles
Browse latest Browse all 11508

Trending Articles



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