我正在尝试编写一个WebPart for SharePoint,它将显示最近上传和修改网站的列表(包括所有文档列表)
为此,我创建了一个SPGridView,我使用SPSiteDataQuery来填充我的(可自定义的)选定列表。我知道SPQuery有ListItemCollectionPosition,但据我所知,这对多个列表不起作用,并且一次做一个废旧排序/分页。
这是我所拥有的片段:
Dim query As New SPQuery()
Dim lists As String = "<Lists ServerTemplate='101'>"
For Each li As Guid In SelectedLists ' Personalisable Property
lists &= "<List ID='" & li.ToString & "' />"
Next
lists &= "</Lists>"
query.Lists = lists
query.RowLimit = 30 ' This will be the page size and is temporarily hardcoded
' These Id's are all SPBuildInFieldId's converted ToString
query.ViewFields = "<FieldRef ID'" & _filenameId & "' />" &
"<FieldRef ID='" & _modifiedId & "' />" &
"<FieldRef ID='" & _modifiedById & "' />" &
"<FieldRef ID='" & _versionId & "' />" &
"<FieldRef ID='" & _checkedOutToId & "' />" &
"<FieldRef ID='" & _fileSizeId & "' />" &
"<FieldRef ID='" & _createdId & "' />" &
"<FieldRef ID='" & _createdById & "' />"
query.Webs = "<Webs Scope='Recursive' />"
query.Query = "<OrderBy><FieldRef ID='" & _modifiedId & "' Ascending='FALSE' /></OrderBy>"
Dim temp as DataTable = objWeb.GetSiteData(query)
For Each row As DataRow In temp.Rows
Dim aRow = dtTable.Rows.Add()
' Get List Information
Dim listId As Guid = New Guid(row.Item("ListId").ToString)
Dim thisList As SPList = objWeb.Lists(listId)
Dim fileName As String = row.Item(_filenameId).ToString
aRow.Item("DocIcon") = "/_layouts/15/images/" & Utilities.SPUtility.MapToIcon(objWeb, fileName, "")
aRow.Item("FileName") = fileName
aRow.Item("FileLink") = objWeb.Url & "/" & thisList.Title & "/" & fileName
aRow.Item("ListName") = thisList.Title
aRow.Item("ListLink") = objWeb.Url & "/" & thisList.Title
aRow.Item("Modified") = row.Item(_modifiedId).ToString
aRow.Item("ModifiedBy") = New SPFieldLookupValue(row.Item(_modifiedById).ToString).LookupValue
aRow.Item("Version") = row.Item(_versionId).ToString
aRow.Item("CheckedOutTo") = New SPFieldLookupValue(row.Item(_checkedOutId).ToString).LookupValue
aRow.Item("FileSize") = row.Item(_fileSizeId).ToString
aRow.Item("Created") = row.Item(_createdId).ToString
aRow.Item("Author") = New SPFieldLookupValue(row.Item(_createdById).ToString).LookupValue
Next
此DataTable设置为我的SPGridView的源,并允许分页(我当前正在使用SPGridViewPager),但它将始终从查询返回完整的文档集合,这将导致一些开销是很多文件。
我想要的是能够在查询本身中进行分页,以便它只返回当前页面的正确文档(一次约30个),但我正试图实现这一目标。 / p>
我是否缺少一个解决方案,允许我以修改顺序查询预定的一组列表,并在查询时分页?
提前致谢并对任何不良措辞/格式表示道歉,这是我在本网站上的第一个问题。
答案 0 :(得分:0)
这种情况有一种解决方法,但它可能不是最佳选择&#39;如果你有庞大的数据量。
&#34;想象一下如果我们想在一个页面中显示25条记录&amp;用户想要导航到第2页。
uint recordsPerPage = 25;
uint pageNumber = 2;
所以我们查询的rowLimit属性应该是25 * 2 = 50。&#34;
https://nivas07.wordpress.com/2010/06/15/paging-using-spsitedataquery/