Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7014435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:31:14+00:00 2026-05-27T22:31:14+00:00

On a pageLoad event I want to go to two different SharePoint Lists and

  • 0

On a pageLoad event I want to go to two different SharePoint Lists and get the first ListItem from one list and an the last ListItem in another. I don’t know any of the ListItem ID’s so I guess this needs to be done through the list index – just not sure how to implement this. Having got a handle on the List can someone advise (using c#) the best way to get the first and last items for the scenario outlined above?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:31:14+00:00Added an answer on May 27, 2026 at 10:31 pm

    The condition “first item” and “last item” is not very clear. Assuming you want to retrieve the first and the latest created item. Important to note is that retrieving items via the index of the SPListItemCollection can be slow for large lists since accessing SPList.Items returns all items of the list. That’s why I suggest using a CAML query:

    SPList list = // some list;
    SPQuery query = new SPQuery();
    query.RowLimit = 1;
    query.Query = "<OrderBy><FieldRef Name='ID' /></OrderBy>";
    
    return list.GetItems(query).Cast<SPListItem>().FirstOrDefault();
    

    For the “last item” you have to reverse the ordering:

    <OrderBy><FieldRef Name='ID' Ascending='FALSE' /></OrderBy>
    

    If you want to get the last and the first item based on another condition you just have to change the order by field.

    Update:
    Even better would be to order by the ID field. With that you could achieve the same result.
    Not only better, the created field could have been changed through code as pointed out by @Kobi.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List (Of MyObject) binding to a GridView in the Page_Load event.
As per requirement I disabled all validation controls in page on PageLoad event in
JavaScript is used where one want to do something on the client side purely,
So my problem is that I want to add an event handler to a
I have a listview and want to change its style to display:none on pageload
I have a problem while writting event for ImageUpload User control. I want to
I am using a tinyMce editor in our website. At the first pageload I
i have 5 checkboxes in my vb.net webform i want when two checkboxes are
I alway have a case where I have one .js file which contain event
I want to delete record on page load event ... using vb.net Protected Sub

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.