3

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?

  • why don't you use, allowpaging=true for gridview ? – Muhammad Raja May 3 '13 at 11:32
  • actually, I need to make paging for asp repeater, but I train on this example. – alisa May 3 '13 at 11:34
3

I resolved the problem sorting items by ID instead of Created field. So I think problem is in datetime format, I didn't find how to fix it.

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.