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 6057639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:30:39+00:00 2026-05-23T08:30:39+00:00

I have a table with items that are displayed by their SortOrder. The SortOrders

  • 0

I have a table with items that are displayed by their SortOrder. The SortOrders are not incremented very well, with values skipping anywhere from 1-100. What I want to do is flip-flop the SortOrder values of two items that are closest together, without necessarily knowing how close together they are. For example:

ItemX.SortOrder = 5;
ItemY.SortOrder = 26;

Assume no items have a sort order between 5-26.

My code needs to switch this to:

ItemX.SortOrder = 26;
ItemY.SortOrder = 5;

For some reason, my code is switching SortOrders with random items, such that:

ItemX.SortOrder = 5;
ItemY.SortOrder = 26;
ItemZ.SortOrder = 34;

Becomes:

ItemX.SortOrder = 34;
ItemY.SortOrder = 26;
ItemZ.SortOrder = 5;

I think its because the results of my query aren’t ordered the way I am picturing them. Here is my query code. If anything else is needed, just let me know.

itemToSwitch = DataSource.Items.Where(item => item.SortOrder > currentItem.SortOrder).First();
int? next = itemToSwitch.SortOrder;
int? previous = currentItem.SortOrder;
currentItem.SortOrder = next;
itemToSwitch.SortOrder = previous;

Sorry if my question is difficult to read or jumbled. I’m trying to be as clear as possible.

  • 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-23T08:30:39+00:00Added an answer on May 23, 2026 at 8:30 am

    I’m suspecting you actually want:

     var sorted = DataSource.Items.OrderBy(item => item.SortOrder);
    

    If you’re reusing it, a .ToList() might help

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

Sidebar

Related Questions

I have a table of items that need to be displayed in a certain
I have a table full of items that each have a unique ItemID .
let's say that I have a table called Items (ID int, Done int, Total
I have a following table using MVC that shows number of items the user
I have a recordset loop that creates a table, and every 9 items it
I'm working on a very basic shopping cart system. I have a table items
I have successfully loaded the muscleName items into a table view but am not
I have a feed of items displayed in table cells, part of which is
I have a History Table in SQL Server that basically tracks an item through
I have a question: I have two MSSQL tables, items and states, that are

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.