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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:23:25+00:00 2026-06-09T04:23:25+00:00

I have recently found a strange behaviour inside of the ASP.NET DropDownList that I

  • 0

I have recently found a strange behaviour inside of the ASP.NET DropDownList that I hope someone could explain.

Basically the problem I am running into is when databinding prior to postback and then setting the SelectedValue to a value that doesn’t exist within the list of dataitems the call simply has no effect. However on postback the same call will fail with a ArgumentOutOfRangeException()

‘cmbCountry’ has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

I’m using the following code.

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        cmbCountry.DataSource = GetCountries();
        cmbCountry.DataBind();

        cmbCountry.SelectedValue = ""; //No effect
    }
    else
    {
        cmbCountry.SelectedValue = ""; //ArgumentOutOfRangeException is thrown
    }
}

protected List<Country> GetCountries()
{
    List<Country> result = new List<Country>();

    result.Add(new Country() { ID = Guid.NewGuid(), Description = "Test" });
    result.Add(new Country() { ID = Guid.NewGuid(), Description = "Test1" });
    result.Add(new Country() { ID = Guid.NewGuid(), Description = "Test2" });
    result.Add(new Country() { ID = Guid.NewGuid(), Description = "Test3" });

    return result;
}

public class Country
{
    public Country() { }
    public Guid ID { get; set; }
    public string Description { get; set; }
}

Could someone please clarify the cause of this behaviour for me and advise if there are any workarounds?

  • 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-09T04:23:26+00:00Added an answer on June 9, 2026 at 4:23 am

    I’m not sure why it was designed this way, but the DropDownList only throws this exception on PostBack… here’s the setter code from ILSpy:

    public virtual string SelectedValue
    {
        get { ... }
        set
        {
            if (this.Items.Count != 0)
            {
                if (value == null || (base.DesignMode && value.Length == 0))
                {
                            this.ClearSelection();
                    return;
                }
                ListItem listItem = this.Items.FindByValue(value);
    
    
    /********** Checks IsPostBack here **********/
                bool flag = this.Page != null &&
                            this.Page.IsPostBack &&
                            this._stateLoaded;
                if (flag && listItem == null)
                {
                    throw new ArgumentOutOfRangeException("value",
                        SR.GetString("ListControl_SelectionOutOfRange", new object[]
                            {
                                this.ID,
                                "SelectedValue"
                            }));
                }
                if (listItem != null)
                {
                    this.ClearSelection();
                    listItem.Selected = true;
                }
            }
            this.cachedSelectedValue = value;
        }
    }
    

    You can get around this by setting the SelectedValue to null instead of an empty string.

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

Sidebar

Related Questions

I have recently found out that there exists a method called nth_element in the
I have recently found out that no argument constructor and multiple argument constructor cannnot
I am a windows dev, but I have recently found that I need to
I have a project that uses JQuery-UI. I recently found formee, which is a
We've recently upgraded one of our SSRS2005 servers to SSRS2008 and have found that
i am on windows/apache/mysql/php setup. i have recently reinstalled PHP. but i found that
I recently have found a strange occurrence in IE8 & FF. The designers where
I have recently found that Matlab can use LaTeX character sequences. However, they only
I have recently found out that anything Swing(NetBeans, IDEA) is excruciatingly slow to paint
On my Asp.Net MVC 3 site I have an error logging functionality that sends

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.