So the steps to retrieve an item from a list view with pages at some n position are -
1. Retrieve the previous page last SPList item. Use this splist item to get the column information from the splist item. These column details will be used for pagination.
2. Create the SPListItemCollectionPosition object using the column details fetched in step 1.
3. Set the SPQuery.ListItemCollectionPosition property with the value fetched in step 2.
4. Pass SPQuery object in SPList.GetListItems function i.e. assetList.GetItems(query). GetItems method returns the paged list items.
Note: Most important part of pagination is forming the string to retrieve the data in pages.
ListItemCollectionPositionNext="Paged=TRUE&p_ID=#id#&CustomColumnInternalName=#colValue#&PageFirstRow=#row#" where p_ID is SharePoint List "ID" Column Name, #row# is the row number e.g. Let's consider page size=5 and total item count=10 and user wants to retrieve page "5" then #row# value will be "41",
#id# is SharePoint list Item "ID" column Value, CustomColumnInternalName is any custom/inbuilt column name on which you are doing item sorting and #colValue# is the column value.
Note: User has to specify the column name in "ListItemCollectionPositionNext" string only when CustomColumnInternalName is being used for sorting the data. In short, if CAML query contains any custom column/inbuild column for sorting, then that column should be specified in the ListItemCollectionPositionNext string.
Responses
0 Respones to "Programmatically Retrieve a particular item from the list\View in SharePoint"
Post a Comment