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

  • Home
  • SEARCH
  • 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 7581963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:19:26+00:00 2026-05-30T18:19:26+00:00

in an mvc 1 aspx view I’m adding a dropdown list for countries, sorted

  • 0

in an mvc 1 aspx view I’m adding a dropdown list for countries, sorted by alphabetical order using a foreach loop:

<div class="row">
   <label>Country</label>
   <select name="registration-country" id="registration-country">
      <%foreach (var country in countryList) { %>
         <option value ="<%=country.CountryGUID %>" ><%= country.CountryName %></option>
      <% } %>
   </select>
</div>

The only way I can think of is:

<div class="row">
   <label>Country</label>
   <select name="registration-country" id="registration-country">
      <%foreach (var country in countryList) { %>
         <option value ="<%=country.CountryGUID %>" se><%= country.CountryName %></option>
      <% } %>
      <option selected="selected" value="79118727-F7AC-4E38-BB7D-DC31A66E111F">United Kingdom</option>--%>
    </select>
</div>

But this just adds another option at the end, I could always remove the UK entry in the list, but still would ruin the sorting.

I’ve been trying to insert an if statement inside but I can’t figure it out so I would appreciate any heads up.

Thanks!!!

  • 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-30T18:19:27+00:00Added an answer on May 30, 2026 at 6:19 pm

    You could have an if statement in the foreach loop which optionally renders one of the two option elements based on whether the item is selected or not.

    You could also conditionally render the selected attribute only if the option is selected, that might make the code a little less readable, but the duplication would be limited.

    Finally, and what I would probably go with is to create a helper which renders the option and you can pass a flag to it if selected should be included or not, then your loop will just be calling the helper with the correct arguments depending on whether it should be selected or not.

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

Sidebar

Related Questions

I'm using the spark view engine with my asp.net mvc application. In my aspx
I am using ASP.NET MVC 2 & 3 with aspx View not Razor View,
I am using FckEditor in Create.aspx page in asp.net mvc application. Since I need
I am trying to convert a MVC aspx page into a Razor view. <%@
If you are using Ajax.BeginForm() with multiple submit buttons similar to this: // View.aspx
I have a Microsoft MVC project with an action Foo whose view (Foo.aspx) contains
I want to load another controller's view using MVC. I do it using something
I am building an ajax form using the MVC Ajax Helpers: http://msdn.microsoft.com/en-us/library/dd505013.aspx The code
I have an ASP.NET web page(Not MVC ) (HomePage.aspx) and another page (PRiceList.aspx).I have
I am following the following tutorial ( http://www.highoncoding.com/Articles/642_Creating_a_Stock_Widget_in_ASP_NET_MVC_Application.aspx ) on using ajax to render

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.