DropDownList SelectedIndexChanged not firing
Is there a trick to getting a SlectedIndexChanged event to fire on a DropDownlist control?
No matter how I select an item this event does not fire.
I ahev checked my code, I can do even handling for any of the other controls in the form but nothing on this DropDownList.
Thansk in advance.
[305 byte] By [
fhunter] at [2008-1-4]
Hi fhunter,
Have you tried getting it to work in a fresh project?
1) Add a ComboBox
2) Add some list items by selecting the ComboBox, clicking on Items in the property grid, and then writing a couple of lines
2) Set the DropDownStyle to DropDownList
3) Double-click the ComboBox
4) Add in the SelectedIndexChanged event handler: MessageBox.Show("Test");
5) Run
When you select one of the items does the MessageBox show up? If not, then it probably isn't your code causing the problem. If so, then in your app that isn't working, you might want to make sure that the event handler is attached to the correct ComboBox's SelectedIndexChanged event. Let me know if the above doesn't work.
Thanks,
Scott Morrison
WindowsForms PM
Microsoft Corp.
Hi I have the similar problem w/o the event firing for dropdownlist when i pass a function at selected change event..any further help pls!
thanx
I'm having a similar problem where no events are firing (_Click, _SelectedIndexChanged, etc.), but this is only happening with one project. Other solutions I'm working on will click and fire perfectly. Copying working code or setting up simple test pages to test the events in the solution with the problem doesn't help. This is VisualStudio.NET 2003 with .NET 1.1
Thanks to anyone who has a potential solution.
I run into this bug occasionally. Today, I fixed it by fixing up some of the page HTML.
In my case, I had had a table nested within a table. I ended up deleting the outer table and somehow ended up with an orphan <strong> tag above my <table> tag. In the HTML window, this is underlined in red as invalid but, of course, you never see this if you are editing in Design view and just looking at that and your compiler output.
Once I deleled the bad nesting, the event fired normally.
So, start by checking your HTML.
I have had and am again having this same bug of ddl SelectedIndexChanged not firing.
When I select a new value on the ddl, the page posts back, the Page_Load function is invoked as PostBack, but the Event handler is never called. I have checked the handler logic in InitializeComponent; it is fine.
Yes, Autopostback is set true.
I use this event all the time. It works on most pages with no problem.
It will not work on the current page I am on, no matter what I do.
I am working in VS, .Net Framework 1.1, developing a webform. All other controls on the webform work fine - buttons, checkboxes and datagrid select.
There are no visible HTML errors on the html page.
I have no clue what else to look at or try.
I would greatly appreciate any insight or direction on where to go to get some actual help with this.
tim
We had same kind of a problem yesterday: the SelectedIndexChanged event of a radiobuttonlist did not fire, no matter what. But the answer was simple, luckily. We had <form> tags in two places in our page, first one on the main .aspx page and the second one on one of the user controls of that .aspx page. We removed the <form> tag from the user control and now the radiobuttonlist works fine! Run the sql and make sure your DataValueField returns Unique values.
Hello,
I have found that when I cut a control off of a form in design view and then paste it inside another container control (eg a GroupBox) that the Handles clause of my pre-existing event code gets stripped off. Since that is at the end of the method declaration, I usually end up pulling my hair out for a while until I think to check that.
I too was experiencing what others have reported - the postback occurs, but the SelectedIndexChanged event is not called.
I think I've found a definitive cause for this and a workaround.
It seems that this event will only fire if the Value property changes. A bit of a bummer if you want different items to return the same value. (I got into this because the same timezone is called different things in different parts of the world.)
The "quick and dirty" code fragments below show the workaround
To load the list (unbound)
N = 0
While dr.Read 'dr is a DataReader
lstTimezones.Value = N.ToString & "|" & dr(0)
... additional code
N = N +1
End While
In the SelectedIndexChanged event:
ValueSplit() As String = Split(lstTimezones.SelectedValue,"|")
TimezoneCode = ValueSplit(1)
Is this an HTML thing or a Microsoft thing? I'd be interested in knowing.
Hi,
I had the same kind of problem. Hema's solution worked out.
Thanks,
Chakri.
I had the same problem but whenI made auto postback property true, it worked
Thanks
Sree
Oh !!
hours of testing and i was finally able to figure this out.
I had EnableViewState turned off with my .aspx page header.
when the ViewState is not saved it reverts back to the First Item as the Selected Index. Selecting the First Item then does not trigger a SelectedIndexChange Event.
make sure EnableViewState is true both on the control and on the page.
Manpreet.
ya Manpreet's solution works fine .............
even I was facing the same problem & enabling Viewstate Works through it..
Thanx All :-)..
Inderdeep..
I also had the same prob ... now its fine..