I'm trying to make a webpart with list items paging. I followed this link http://www.directsharepoint.com/2011/03/step-by-step-guide-to-implement-paging.html and on SharePoint 2010 server it works good, but on 2013 it doesn't.
public SPListItemCollection GetTestItems(string pagingInfo)
{
SPWeb objWeb = SPContext.Current.Web;
SPListItemCollection collection;
SPQuery objQuery = new SPQuery();
objQuery.RowLimit = (uint)MaxItemsOnPage;
objQuery.Query = Camlex.Query().OrderBy(i => i[SPBuiltInFieldId.Created] as Camlex.Desc).ToString();
objQuery.ViewFields = Camlex.Query().ViewFields(i => i["Title"]);
if (!string.IsNullOrEmpty(pagingInfo))
{
SPListItemCollectionPosition position = new SPListItemCollectionPosition(pagingInfo);
objQuery.ListItemCollectionPosition = position;
}
collection = objWeb.Lists["testList"].GetItems(objQuery);
return collection;
}
When pagingInfo string is not null, it means when I push "next" and pagingInfo = "Paged=TRUE&p_ID=3&p_Created=20130502%2022%3A19%3A00", the query return collection with 0 items.
I tried to remove p_Created=20130502%2022%3A19%3A00 from paging info string and don't use ordering in query it works. But I need to sort it by Created field, descending.
I make p_Created value like
SPEncode.UrlEncode( Convert.ToString(collection[collection.Count - 1]["Created"]));
Maybe datetime formating in incorrect for sharepoint 2013 or they changed something in pagingInfo string format?