dropdown not working

James

Well-known member
Joined
Oct 3, 2002
Messages
78
I have a drop down list box that does not post back properly. When the drop down list item changes the OnSelectedIndexChanged event triggers it run the Page_Load subroutine with no problems, but it does not run the ddDetails_SelectedIndexChanged subroutine like its suppose to. Does anyone know why? All my other drop downs work fine. I dont know whats happening. I do not get a run-time error. Drop down code is below

webcontrol:
<asp:dropdownlist id="ddDetails" runat="server" OnSelectedIndexChanged="ddDetails_SelectedIndexChanged" AutoPostBack="True">

code behind:
Sub ddDetails_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
getIt()
End Sub

James
 
do you have a handler...
Code:
Sub ddDetails_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles ddDetails.SelectedIndexChanged
getIt()
End Sub
 
I do have a handler. The code post does not because I removed it to see if it would help. It doesnt.

James
 
Dont not specify the handler in both the code-behind and the aspx page.

Hence remove:
OnSelectedIndexChanged="ddDetails_SelectedIndexChanged"

and on the code-behind

Public Sub Poopy(ByVal sender As Object, e As EventArgs) Handles ddDetails_SelectedIndexChanged

put your big bad code here

End Sub

If that is not the problem, then verify that the state is being kept, the function/sub that loads the dropdown is NOT being run on a post back. I ran into this big time when I was dynamically creating the menues from a db.

Hope that helps.
 
The code is in a code behind. I remove the onselectChange from my dropdown but it still doesnt work. How do I know if the state is being kept? The sub that loads the dropdown is the Page_Load it run and loads the dropdown but the sub that is call when I change the selected item does not run.

James
 
Did you design the form in the designer?

trace this (code-behind)....
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
    place something here
else
    place something here    
end if
 
Yes I designed the form in the designer.

When I change an Item in the drop down the code should start with the Load_Page sub. Once that finishes then the sub for my dropdown onselectchanged should run. I know that the following code in my Load_Page works because I step through it in debug mode:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
place something here
Else
place something here
End If
end sub

However, my drop down onselectchanged does not run The code stop after the Page_Load sub ends.

James
 
Yes the dropdown has a runat=server. The text and values for my dropdown are:

value text
1 Dallas
2 Dallas
3 Dallas
1 NY
2 NY

When I select any of the "Dallas" items my code works. But when I select a different item like "NY" my code doesnt work. Any thoughts?
 
Robby, yes thats whats happening now. I think I solve the problem. I dont think I can have duplicate values in a dropdown control. I changed the following and it works. Can a dropdown have duplicate value even if the text is different?

1 Dallas 1 Dallas
2 Dallas 2 Dallas
3 Dallas to 3 Dallas
1 NY 4 NY
2 NY 5 NY

James
 
Thanks Robby that answer the question to my problem. I hate finding out the hard way. But it seem to be the best way to learn at times.

James
 
Back
Top