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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:51:54+00:00 2026-05-29T15:51:54+00:00

EDIT: Solved. An attempt to bind a DataTable to the DDL accidentally happened twice

  • 0

EDIT: Solved. An attempt to bind a DataTable to the DDL accidentally happened twice once while not checking the page’s PostBack status. Once the redundant attempt to bind was removed the problem went away. Thanks for the assistance everyone.

I have an aspx page and some code behind that feature a drop down list (ddlLocationState) or US states in alphabetical order. However no matter what item is selected, if I do ddlLocationState.SelectedItem/Value/Index it’s always “Alaska” and “0”. Every single time. Even in the SelectedIndexChange event handler.

Here’s where the DDL is declared in the aspx page (this is the only reference to it in the page):

<tr>
   <td>&nbsp;</td>
   <td class="textBlue"><label>State: </label></td>
   <td>
      <asp:DropDownList runat="server" ID="ddlLocationState" style="width: 250px;"/>
   </td>
</tr>

Here’s the code where the contents of the DDL are setup up:
private void BindStates()

  private void BindDDL()
  {
     //Get all state info:
     // Populate a DataTable called "sdt" with two columns, name (a state)
     // and "id" (a number from 0 to 49)

     //Bind the DataTable "sdt":
     this.ddlLocationState.DataSource = sdt;
     this.ddlLocationState.DataTextField = "name";
     this.ddlLocationState.DataValueField = "id";
     this.ddlLocationState.DataBind();
  }

Here’s some code-behind trying to get the currently selected value:

private void ddlLocationState_SelectedIndexChanged(object sender, EventArgs e)
{
   System.Diagnostics.Debug.WriteLine("on index changed:   " +  dlLocationState.SelectedItem.Value.ToString());
}

Here’s where BindDDL is called:

protected void Page_Load(object sender, EventArgs e)
      {
         this.pnlLocationMaintenance.Visible = false;
         this.LocationSortDirection = "asc";
         this.LocationSortField = "address";
         this.BindStates();
         this.dgLocations.CurrentPageIndex = 0;
         this.BindLocations();

         if (!Page.IsPostBack)
         {
            BindDDL();
         }
         ddlLocationState.SelectedIndexChanged += new EventHandler(ddlLocationState_SelectedIndexChanged);
      }

Why is the ddlLocationState.SelectedItem/Value/Index always the same, even in the selected index change event handler?

  • 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-29T15:51:57+00:00Added an answer on May 29, 2026 at 3:51 pm

    This will happen if you are databinding on page_load without checking to see whether you are in a postback state or not. It is my assumption from your described symptoms that this is what is happening.

    In your PageLoad(…) method you need to:
    if (!Page.IsPostBack)
    {
    BindDDL();
    }

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

Sidebar

Related Questions

Edit : Solved, there was a trigger with a loop on the table (read
Edit: Solved. Hi, I'm starting with Qt, I try to connect a slot to
edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
Edit: I have solved this by myself. See my answer below I have set
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
EDIT: Solved with a hack for now. Added at line 473: if (isset($this->_termsFreqs[$termId][$docId])) {
EDIT: Just to make sure someone is not breaking their head on the problem...
EDIT: solved. ans var needed to be set to 0 in every iteration.That was
EDIT: SOLVED--SOURCE CODE HERE: http://matthewdowney20.blogspot.com/2011/09/source-code-for-roku-remote-hack.html thanks in advance for reading and possibly answering this.

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.