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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:46:57+00:00 2026-05-25T15:46:57+00:00

I get the wrong value from my Dropdownlist (ddlCity). I always get the default

  • 0

I get the wrong value from my Dropdownlist (ddlCity). I always get the “default” value, the value the list has when the page load. What am I doing wrong?

<asp:DropDownList ID="ddlCountry" runat="server"AutoPostBack="true"></asp:DropDownList>

<asp:DropDownList ID="ddlCity" runat="server"></asp:DropDownList>

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DataTable CountryTable = CategoryAccess.GetCountry();
        ddlCountry.DataSource = CountryTable;
        ddlCountry.DataTextField = "CountryName";
        ddlCountry.DataValueField = "CountryID";
        ddlCountry.DataBind();
    }
    else
    {
        String CountryID = ddlCountry.SelectedValue;

        DataTable CityTable = CategoryAccess.GetCitysInCountry(CountryID);
        ddlCity.DataSource = CityTable;
        ddlCity.DataTextField = "City";
        ddlCity.DataValueField = "CityID";
        ddlCity.DataBind();
    }
}

protected void btnUpdate_Click(object sender, EventArgs e)
{
    string id = (ddlCity.SelectedItem.Value);
    //This is where id is wrong, unless I choose the first city in the list.
}

Database code:

ALTER PROCEDURE GetCountry
AS          
SELECT        CountryID, CountryName
FROM          tblCountry  



ALTER PROCEDURE GetCitysInCountry
@CountryID INT
AS          
SELECT        tblCitysInCountry.CityID, tblCitysInCountry.CountryID, tblCity.City, tblCountry.CountryName
FROM          tblCitysInCountry LEFT JOIN
                         tblCity ON tblCitysInCountry.CityID = tblCity.CityID LEFT JOIN
                         tblCountry ON tblCitysInCountry.CountryID = tblCountry.CountryID
WHERE         (tblCitysInCountry.CountryID = @CountryID)
  • 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-25T15:46:58+00:00Added an answer on May 25, 2026 at 3:46 pm

    Page_Load occurs before the selected index is set during postback. Try moving your second set of databinding code to a more appropriate place – maybe in the event handler that ddlCountry will be invoking (SelectedIndexChanged?)


    There certainly seem to be a lot of hits on Google for “page_load SelectedValue“, which all tend to indicate the value cannot be accessed during Page_Load.

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

Sidebar

Related Questions

I don't get what I'm doing wrong. I'm trying to populate a form from
I am fetching some value from another page using jQuery .get() like this <input
I've written a function to get the maximum value from a list of nested
What am I doing wrong to get this error? replacements = {} replacements[**] =
What's wrong in here, I always get some nasty errors even if the same
What am I doing wrong here? I'm trying to get started with jQuery UI
I am trying to get a cell value from the selected item of a
Can anybody please tell me how to get double and int value from a
I have the following code and when i try to get a value from
I need to get a value from my cursor. The value needs to be

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.