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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:42:59+00:00 2026-05-27T00:42:59+00:00

I have a few web sites and load articles on the main page. I

  • 0

I have a few web sites and load articles on the main page. I can set ranking on the articles to display them in different order but the ordering could be different on the various sites for the articles.

The code I have to order the articles sets the same order for all sites:

    string officeLocation = "";
    // office location could be either World, Europe, Africa, America, Asia, Pacific

    var result = articles.Select(a => new
    {
        Title = a.Title,
        Url = a[SPBuiltInFieldId.FileRef],
        Byline = a[Constants.FieldNames.Byline],
        ArticleDate = a[Constants.FieldNames.ArticleStartDate],
        RankWorld = a[Constants.FieldNames.World],
        RankEurope = a[Constants.FieldNames.RankEurope],
        RankAfrica = a[Constants.FieldNames.RankAfrica],
        RankAmerica = a[Constants.FieldNames.RankAmerica],
        RankAsia = a[Constants.FieldNames.RankAsia],
        RankPacific = a[Constants.FieldNames.RankPacific],
    });

    rptArticles.DataSource = result.OrderBy(a => a.RankWorld);
    rptArticles.DataBind();

The code sets all ranking to whatever RankWorld is (1-6).

If the string officeLocation (that is passed on to the method) is Europe then I want to order by a.RankEurope, if officeLocation is Asia order by a.RankAsia and so on.

How can I best achieve this (.NET 3.5)?

Thanks in advance.

  • 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-27T00:43:00+00:00Added an answer on May 27, 2026 at 12:43 am

    Assuming you have a fixed set of locations (which by definition, you must have as you’re stating them in the anonymous type) then you could just use a switch:

    string officeLocation = "";
    // office location could be either World, Europe, Africa, America, Asia, Pacific
    
    var result = articles.Select(a => new
    {
        Title = a.Title,
        Url = a[SPBuiltInFieldId.FileRef],
        Byline = a[Constants.FieldNames.Byline],
        ArticleDate = a[Constants.FieldNames.ArticleStartDate],
        RankWorld = a[Constants.FieldNames.World],
        RankEurope = a[Constants.FieldNames.RankEurope],
        RankAfrica = a[Constants.FieldNames.RankAfrica],
        RankAmerica = a[Constants.FieldNames.RankAmerica],
        RankAsia = a[Constants.FieldNames.RankAsia],
        RankPacific = a[Constants.FieldNames.RankPacific],
    });
    
    switch (officeLocation)
    {
        case "World": result = result.OrderBy(a => a.RankWorld); break;
        case "Europe": result = result.OrderBy(a => a.RankEurope); break;
        case "Africa": result = result.OrderBy(a => a.RankAfrica); break;
        case "America": result = result.OrderBy(a => a.RankAmerica); break;
        case "Asia": result = result.OrderBy(a => a.RankAsia); break;
        case "Pacific": result = result.OrderBy(a => a.RankPacific); break;
        default: throw new Exception("Unexpected location: " + officeLocation);
    }
    
    rptArticles.DataSource = result.OrderBy(a => a.RankWorld);
    rptArticles.DataBind();
    

    Obviously, you need to decide how best to handle an unexpected location.

    Note that, ideally, I would have just assigned the OrderBy function to a Func<T,R>, but and only have one OrderBy call, but you can’t do that here due to the anonymous type.

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

Sidebar

Related Questions

I have a few web servers behind an Amazon EC2 load balancer. I'm using
I have a few projects where we have 3-5 different web.config.xxx that should meet
I have learned that browsers can only load a few files from the same
Over the last few days I have noted a few web sites that demonstrated
I have about 50 web-sites, load-balanced across 5 web-servers. They all use Enterprise Library
I have this senario. We have an application server that contains a few web
Have an ASP.net web app which works fine for a few days, but then
A few test scenarios have been recorded using CodedUI test template for my web
I have a web application where the first request may take a few seconds
I have written a mini web-server which needs to serve up a few static

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.