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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:20:31+00:00 2026-05-27T01:20:31+00:00

Today I found a weird problem, I was trying to fire a DropDownList SelectedIndexChanged

  • 0

Today I found a weird problem, I was trying to fire a DropDownList SelectedIndexChanged event but it just didn’t work at all. After checking with other DropDownLists I have I noticed the only difference is that they are being filled using a datasource while this one is being filled manually in the backend.

Here is what I have:

<asp:DropDownList ID="DDDynAccount" runat="server" 
onselectedindexchanged="DDDynAccount_SelectedIndexChanged" 
AutoPostBack="true"></asp:DropDownList>

Then the Backcode when loading it:

DDDynAccount.Items.Add(new ListItem("ANY", "%"));
DDDynAccount.Items.Add(new ListItem("SELECT", "%"));

The event which is not being fired:

public void DDDynAccount_SelectedIndexChanged(object sender, EventArgs e) {
    string s = ""; // I have a breackpoint here
}

If I do that, the event is never fired.
I’ve tried setting on and off the AutoPostBack. Nothing.
I’ve tried making a new control from scratch. Nothing.
I’ve also tried to call to Databind() once I’ve added its items manually but using no Datasource. Again nothing.

I have another DropDownList in the same page that works. The only difference is that that one is using a datasource. So I tried this:

    List<ListItem> ds = new List<ListItem>();
    ds.Add(new ListItem("ANY", "%"));
    ds.Add(new ListItem("SELECT", "%"));
    DDDynAccount.DataSource = ds;
    DDDynAccount.DataBind();

And that will work.

My question is simple. WHY? Why cannot I fire the event if Im not using a datasource? Or there is any other problem?


I’m using .Net4 with C# in a Web Application.


Update: Ok Im sorry for this but, after checking the code wrotten here I realized a little detail, the Items I was adding manually had the same value, changing it the problem is fixed. I presume the event is not fired because the value hasnt changed, despite the “SelectedIndexChanged” should be fired not when the value is changed, but when the index is.

  • 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-27T01:20:32+00:00Added an answer on May 27, 2026 at 1:20 am

    Both items have the same value, so as the first item is selected by default when you select the second item, the Value of the drop down list is not changed so as far as the code is concerned nothing changed and there’s nothing to do.

    Having such code instead:

    DDDynAccount.Items.Add(new ListItem("ANY", "%%"));
    DDDynAccount.Items.Add(new ListItem("SELECT", "%"));
    

    Will trigger the event just fine.

    This is bug with .NET actually – it works only with value assuming it’s unique, and not with the item index.

    As a side note, to avoid adding more and more items each post back, wrap the adding with such statement:

    if (!Page.IsPostBack)
    {
        DDDynAccount.Items.Add(new ListItem("ANY", "%%"));
        DDDynAccount.Items.Add(new ListItem("SELECT", "%"));
    }
    

    Edit: was curious about you saying it worked fine with binding data source so tried for myself. Well, it fails with data source as well. With the code you posted:

    List<ListItem> ds = new List<ListItem>();
    ds.Add(new ListItem("ANY", "%"));
    ds.Add(new ListItem("SELECT", "%"));
    DDDynAccount.DataSource = ds;
    DDDynAccount.DataBind();
    

    Quick view of the HTML source show that the value of each option is actually its text – ANY and SELECT and not the value you tried to assign. To assign the proper value you need such code:

    List<ListItem> ds = new List<ListItem>();
    ds.Add(new ListItem("ANY", "%"));
    ds.Add(new ListItem("SELECT", "%"));
    DDDynAccount.DataTextField = "Text";
    DDDynAccount.DataValueField = "Value";
    DDDynAccount.DataSource = ds;
    DDDynAccount.DataBind();
    

    And you will experience the same problem as with assigning the items one by one as now the value will be the same.

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

Sidebar

Related Questions

It's just been one problem after another today. I just deployed to my production
We just switched to new PHP SDK and JS today. but the problem is
So, after 6 months of hard work finally released my application. Today I found
I was today trying to figure out on working with WebService and found many
I've been searching all day and found several similar issues, but none have resolved
I looked at some Java code today, and I found some weird syntax: public
I just found out today that WPF will ignore CultureInfo.CurrentCulture and always use en-US.
Today I found a strange problem that is I have a Table With a
Today I found one interesting thing. I didn't know that one can't declare a
When I came home today I found all my PHP files infected on Godaddy

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.