SPListItemCollectionPosition class
支援分頁的資料集,以儲存取得清單的特定檢視中的下一個頁面中的資料所需的狀態。
Inheritance hierarchy
System.Object
Microsoft.SharePoint.SPListItemCollectionPosition
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Class SPListItemCollectionPosition
'用途
Dim instance As SPListItemCollectionPosition
public class SPListItemCollectionPosition
Examples
下列程式碼範例會使用SPListItemCollection類別和SPQuery類別的ListItemCollectionPosition屬性,傳回SPListItemCollectionPosition物件,儲存有關的資訊,其中每個資料頁結束集合中的項目,並會顯示項目標題的 10 個資料列的群組中的物件。此範例假設清單是文件庫或清單中已啟用資料夾。
這個範例要求using指示詞 (Imports Microsoft Visual Basic 中), Microsoft.SharePoint和Microsoft.SharePoint.Utilities命名空間。
Dim site As SPWeb = SPControl.GetContextWeb(Context)
Dim list As SPList = site.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").ToString()) & _
"<BR>")
Next listItem
query.ListItemCollectionPosition = _
listItems.ListItemCollectionPosition
i += 1
Loop While Not (query.ListItemCollectionPosition Is Nothing)
SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.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"].ToString()) +
"<BR>");
}
oQuery.ListItemCollectionPosition =
collListItems.ListItemCollectionPosition;
intIndex++;
} while (oQuery.ListItemCollectionPosition != null);
注意事項 |
---|
如需有關如何使用 Language-Integrated 查詢 (LINQ) 查詢來擷取清單項目,在SharePoint Foundation中的資訊,請參閱Managing Data with LINQ to SharePoint。 |
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.