Reputation: 328
I just started SharePoint webpart programming today. I have list called "pagesList" and I want to order its list items using the field "sortField" in descending order. Then I want to get the first item in the list. here is what I tried so far but I don't know how to get the first item in the sorted list to assign it.
if (pagesList != null)
{
SPQuery q = new SPQuery();
q.Query = "<OrderBy><FieldRef Name='sortField' Ascending='False' /></OrderBy>";
SPListItemCollection listItemCollection = pagesList.GetItems(q);
CurrentIssueLinkButton.PostBackUrl = /* the first item of the sorted listitems goes here*/;
}
How can I get the first list item?
Upvotes: 0
Views: 875
Reputation: 203838
Set the RowLimit
of the SPQuery object to one to ensure that at most one item is returned.
Upvotes: 1