Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Here is the code Im using to retrieve the first 4 most upcoming announcements from the OOTB announcements list in sharepoint:

How do I modify this to retrieve the next 4 (5,6,7 and 8) most upcoming events preserving the filters and order bys in my CAML??

Is there a way for me to use an Index variable and iterate?

Or should I go with LINQ's skip and take features?? (I'd like to know how to do it using the CAML query though)

SPList list = web.Lists["Announcements"];

                    SPQuery spQuery = new SPQuery();



//The following CAML query filters to show the 4 most upcoming   announcements.                         
 spQuery.Query = " <Where><And><IsNotNull><FieldRef   Name='Title' /></IsNotNull><Or><IsNull><FieldRef Name='Expires' /></IsNull><Geq><FieldRef   Name='Expires' /><Value   Type='Date'><Today /></Value></Geq></Or></And></Where><OrderBy><FieldRef Name='Created'   Ascending='True' /></OrderBy>";

                    spQuery.RowLimit = 4;
                    SPListItemCollection oListCollection = list.GetItems(spQuery);

                    foreach (SPListItem item in oSPListItemCollection)
                    {
                        // Check if item exists
                        if (item != null)
                        {
                            Label1.Text = item["Title"].ToString();
                        }
                    }
share|improve this question
    
you can get a list item by its index number, why dont use that –  Muhammad Raja Jul 13 '12 at 19:38
add comment

1 Answer

up vote 1 down vote accepted

SPQuery.ListItemCollectionPosition is used for paging in CAML queries, but you can only use saved values of it to go to the page after the query that returned the ListItemCollectionPosition

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.