SPQuery.ListItemCollectionPosition property
取得或設定用來取得下一個資料列集的分頁檢視的清單中的物件。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Property ListItemCollectionPosition As SPListItemCollectionPosition
Get
Set
'用途
Dim instance As SPQuery
Dim value As SPListItemCollectionPosition
value = instance.ListItemCollectionPosition
instance.ListItemCollectionPosition = value
public SPListItemCollectionPosition ListItemCollectionPosition { get; set; }
Property value
Type: Microsoft.SharePoint.SPListItemCollectionPosition
SPListItemCollectionPosition 物件。
備註
ListItemCollectionPosition屬性和RowLimit屬性用於定義在查詢中的分頁。具體來說, SPListItemCollectionPosition物件用來逐一查看集合的n項目中的所有項目一次n所在資料列限制為指定的值。
Examples
下列程式碼範例會使用的SPListItemCollection和SPQuery類別的ListItemCollectionPosition屬性來傳回SPListItemCollectionPosition物件來儲存每個資料頁的項目集合中結束,並顯示項目標題的 10 個資料列群組。此範例假設清單是文件庫或清單中已啟用資料夾。該範例也假設此清單包括內部的名稱為 「 欄位 1 」 的欄位,並使用內部名稱"Field2"的欄位。
注意事項 |
---|
如需有關如何使用 Language-Integrated 查詢 (LINQ) 查詢來擷取清單項目,在SharePoint Foundation中的資訊,請參閱Managing Data with LINQ to SharePoint。 |
這個範例要求using指示詞 (Imports Microsoft Visual Basic 中), Microsoft.SharePoint和Microsoft.SharePoint.Utilities命名空間。
Dim webSite As SPWeb = SPContext.Current.Site.RootWeb
Try
Dim list As SPList = webSite.Lists("Announcements")
Dim query As New SPQuery()
query.RowLimit = 10
query.Query = "<OrderBy Override=\"TRUE\">" & _
"<FieldRef Name=\"FileLeafRef\" /></OrderBy>";
Dim i As Integer = 1
Do
Response.Write(("<BR>Page: " + i + "<BR>"))
Dim listItems As SPListItemCollection = list.GetItems(query)
Dim listItem As SPListItem
For Each listItem In listItems
Response.Write((SPEncode.HtmlEncode(listItem("Title")) & "<BR>"))
Next listItem
query.ListItemCollectionPosition = _
listItems.ListItemCollectionPosition
i += 1
Loop While Not (query.ListItemCollectionPosition Is Nothing)
Finally
webSite.Dispose()
End Try
using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
{
SPList oList = oWebsiteRoot.Lists["Announcements"];
SPQuery oQuery = new SPQuery();
oQuery.RowLimit = 10; oQuery.Query = "<OrderBy Override=\"TRUE\">" +
"<FieldRef Name=\"FileLeafRef\" /></OrderBy>";
int intIndex = 1;
do
{
Response.Write("<BR>Page: " + intIndex + "<BR>");
SPListItemCollection collListItems = oList.GetItems(oQuery);
foreach(SPListItem oListItem in collListItems)
{
Response.Write(SPEncode.HtmlEncode(oListItem["Title"]) +
"<BR>");
}
oQuery.ListItemCollectionPosition =
collListItems.ListItemCollectionPosition;
intIndex++;
} while(oQuery.ListItemCollectionPosition != null);
}