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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:55:54+00:00 2026-06-13T23:55:54+00:00

I have a list which contains The Price The Code I’ve managed to split

  • 0

I have a list which contains

  1. The Price
  2. The Code

I’ve managed to split the list to an array, but I want to further split the array so that I can get the Price and Code separately and sort the Price to ascending order. When the sorting occurs, I need the Code to be sorted together as well because the Price is for that particular Code.

So it will be like this:
Original List:

1588,8DNY;1488,ACNY;1288,7DPE;1888,8HUC;1488,8WNH;

After Splitting to arrPrice:

[1588,8DNY],[1488,ACNY],[1288,7DPE],[1888,8HUC],[1488,8WNH]

2nd Splitting 2ndarrPrice:

[1588],[1488],[1288],[1888],[1488]

2nd Splitting 2ndarrCode:

[8DNY],[ACNY],[7DPE],[8HUC],[8WNH]

Sort Price in ascending order:

[1288],[1488],[1488],[1588],[1888]

Code will be sorted accordingly:

[7DPE],[ACNY],[8HUC],[8WNH]

I am stuck after the 1st splitting.

  if (lblprices.Text != "")
    {
        arrprice = lblprices.Text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

        Array.Sort(arrprice);

        for (i = 0; i < arrprice.Length; i++)
        {
            arr2 = arrprice[i].Split(',');
            SQL2 = "SELECT DISTINCT [TP].[TCode], ";
            SQL2 += "[TP].[TName], ";
            SQL2 += "[TP].[TName_CN],  ";
            SQL2 += "[TP].[TourType], ";
            SQL2 += "[TP].[LastUpdateDate], ";
            SQL2 += "[TP].[ValidityFrom],  ";
            SQL2 += "[TP].[ValidityTo], ";
            SQL2 += "[CL].[CountryCode], ";
            SQL2 += "[CL].[CityName] ";

            SQL2 += "FROM [CL], [TP], [TourItinerary],[TourHotel] ";

            SQL2 += "WHERE [TP].[Activation] = 1  ";
            SQL2 += "AND [TP].[TCode] = '" + arr2[1] + "' ";
            SQL2 += "ORDER BY [TP].[LastUpdateDate] DESC ";

            objConnTour.Open();

            SqlCommand command = new SqlCommand(SQL2, objConnTour);
            SqlDataReader dataReader = command.ExecuteReader();

            if (dataReader.Read())
            {
                html += "<tr><td class=\"border\">" + dataReader["TCode"] + "</td>";
                html += "<td class=\"border\">" + dataReader["TName"] + "</td>";
                html += "<td class=\"border\">" + dataReader["TName_CN"] + "</td>";
                html += "<td class=\"border\">" + dataReader["TType"] + "</td>";
                html += "<td class=\"border\">" + dataReader["LastUpdateDate"] + "</td>";
                html += "<td class=\"border\">" + dataReader["ValidityFrom"] + "</td>";
                html += "<td class=\"border\">" + dataReader["ValidityTo"] + "</td>";
                html += "<td class=\"border\">" + dataReader["CountryCode"] + "</td>";
                html += "<td class=\"border\">" + dataReader["CityName"] + "</td>";
                html += "<td class=\"border\">from&nbsp;<span class=\"price-red\">S$<b>" + arr2[0] + "</b></span><td/></tr>";
            }

            dataReader.Close();

            objConnTour.Close();
        }
    }
    return html;

The code above will not be able to sort the price in ascending order. As you can see in my arr2 split, I need the Code and Price together as I will be retrieving data from database based on the Code.

——–Edit———

Ok so the problem is that if the prices are in the of 1000-1999, it gets sorted perfectly.
But if i have prices that is less than 1000, it will not be sorted in an ascending manner

Example are the screenshots of the results using the code provided by @jekcom

This is when i haven’t split the List and retrieve them raw from the database

Original, Unsorted

And this is the Sorted one using @jekcom’s code

enter image description here

Notice how the Price are not sorted in Ascending manner.

  • 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-06-13T23:55:55+00:00Added an answer on June 13, 2026 at 11:55 pm

    The code you posted doesn’t work since you’re not sorting the array based on Price part of the array. If you have Linq:

    if (lblprices.Text != "")
    {
        arrprice = lblprices.Text.Split(new char[] { ';' }, 
                                        StringSplitOptions.RemoveEmptyEntries);
        var lst = arrprice.OrderBy(x => int.Parse(x.Split(',')[0])).ToList();
    
        for (i = 0; i < lst.Count; i++)
        {
            arr2 = lst[i].Split(',');
    
            //rest of your code ----------------
        }
    

    This should work, in sql terms this should give

    ORDER BY PRICE ASC, [TP].[LastUpdateDate] DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List which contains a list of objects and I want to
I have a python list which contains dictionaries and I want to make a
I have a JTree which contains file/directory, i want to get a list which
I have an array list named newSymptomList which contains a list of Symptom id's
I have a list which contains a collection of objects. How can I search
i have a list which contains sentences split up from a test paragraph. I'm
I have a list which contains an item '\n' in it. I want to
I have a list which contains strings integers and floats. I want to convert
I have a list which contains 1-5 lists within it. I want to return
I have a list which contains a dictionary of ExpandoObjects. Im binding this to

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.