Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown fires, but nothing changes??

Status
Not open for further replies.

jacktripper

Programmer
Dec 5, 2001
124
US
If seen tons of posts about a dropdown event that DOESNT fire, but...

In my case the event is firing for SelectedIndexChanges or TextChanged, but the SelectedValue and SelectedIndex doesn't... Which makes absolutely no sense to me.

So, how can my event be firing, but the selected index and values don't? What am I missing?


Its a simple DDL:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem>Status Changed</asp:ListItem>
<asp:ListItem>Page Name</asp:ListItem>
<asp:ListItem>Status</asp:ListItem>
<asp:ListItem>Changed By</asp:ListItem>
<asp:ListItem>Date Published</asp:ListItem>
</asp:DropDownList>


And the event is (this shows TextChanged, but I've tried SelectedIndexChange and that does the same thing - nothing):
Protected Sub DropDownList1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.TextChanged
Dim thisIndex As Integer = DropDownList1.SelectedIndex
Dim SortBy As String = DropDownList1.Text

Response.Redirect("ListOfPages.aspx?SortBy=" & DropDownList1.SelectedValue)
End Sub
 
Can you remove the Handles and just place the event in your HTML to see if it works there?

...OnSelectedIndexChanged="DropDownList1_TextChanged" AutoPostBack="true">
 

The result is the same if I remove the handle and put it in HTML. The event fires, but no matter what item in the dropdown that I choose, it always says Index 0 and the value of that 1st item.
 
Well, I'm not sure what the problem was.

I gave up, made a new dropdown, and wrote essentially the same code and everything works now.

Who knows? Maybe I did something earlier that goofed it and I just didn't notice. Oh well. Best I leave it alone now!
 
Ok,

1. I think you need to change
Dim SortBy As String = DropDownList1.Text
to
Dim SortBy As String = DropDownList1.SelectedItem.Text

2. Are you manually populating the DropDown (in HTML like you posted)? Check that its not getting rebound on postback or page load

3. Output the results of the event to a label on the page somewhere to see you are getting expected results (comment out the redirect for now)
Code:
Protected Sub DropDownList1_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim thisIndex As Integer = DropDownList1.SelectedIndex
Dim SortBy As String = DropDownList1.SelectedItem.Text

Label1.Text = thisIndex.ToString() & " : " & SortBy

'Response.Redirect("ListOfPages.aspx?SortBy=" & DropDownList1.SelectedValue)
End Sub

It has to be something silly because you are on the right track, and should work like you said

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top