简体   繁体   English

检索排序列表SharePoint 2010 C#的第一个列表项

[英]Retrieve the first list item of a sorted list SharePoint 2010 C#

I just started SharePoint webpart programming today. 我今天才开始进行SharePoint Webpart编程。 I have list called "pagesList" and I want to order its list items using the field "sortField" in descending order. 我有一个名为“ pagesList”的列表,我想使用字段“ sortField”以降序对其列表项进行排序。 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? 如何获得第一个列表项?

将SPQuery对象的RowLimit设置为1,以确保最多返回一项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM