SharePoint 2010中的富名单分页

时间:2014-03-27 11:50:07

标签: c# linq sharepoint sharepoint-2010

我有一个SharePoint列表,其中包含我需要逐页显示的数据。必须要求是能够跳过页面并显示总页数(即1,2,3 ... 15)。 SharePoint是否允许这样做?

到目前为止,我尝试过: CAML:似乎不可能,因为CAML查询需要上一页的元素来显示下一页。

REST:使用/_vti_bin/listdata.svc和LINQ查询:

//VS2010 creates classes for all list items when adding reference to listdata.svc
RootDataContext context = new RootDataContext(new Uri(Utils.ListServiceUrl)); 
context.Credentials = System.Net.CredentialCache.DefaultCredentials;

//this works like a charm, I am able to filter items by category and page them 
//(category is a single lookup)
var query = (DataServiceQuery<NewsItemsItem>)context.NewsItems.
            Where(i => i.CategoryId == 2).
            Skip(3).
            Take(2);

//however, if I need more advanced filtering (Tags is multilookup) I fail 
//(the code below won't work as this approach does not allow to make aggregation 
//queries inside other query)
var query = (DataServiceQuery<NewsItemsItem>)context.NewsItems.
            Where(i => i.Tags.Where(t => t.Id == 3).Count() > 0).
            Skip(3).
            Take(2);

如果你能给我任何建议,我将不胜感激。

1 个答案:

答案 0 :(得分:2)

http://msdn.microsoft.com/en-us/library/ff798478.aspx 跳过linq到sharepoint无法帮助你。因为sharepoint没有一些工具来跳过N值&#34;。

查看这篇文章。如果您按列排序并希望在caml中使用此订单对此列表进行分页,那么它们将非常有用。

http://blogs.msdn.com/b/dbadki/archive/2008/10/08/caml-query-execution-using-pagination-for-custom-columns.aspx

http://blogs.msdn.com/b/colbyafrica/archive/2009/02/19/learning-sharepoint-part-vi-list-pagination.aspx

无论如何,在sharepoint中列出的分页是安静可怕的(我想不仅对我来说)。因为我只能像以前那样分页 - 下一个&#34;不是&#34; 1 2 3 4 5 ....&#34;页面