Clifton Bardwell
asked on
Getting Text Value of a DropDownList
This question is about ASP.Net/VB.Net with the VS.Net 2008 platform.
I have a DropDownList on my page. I filled it during the page load. I also have a button on the form. The code to the button looks something like this:
The DropDownList doesn't seem to react to SelectedIndexChanged either.
TIA
I have a DropDownList on my page. I filled it during the page load. I also have a button on the form. The code to the button looks something like this:
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
MsgBox(ddlStates.Text)
End Sub
The issue seems to be that, no matter what the user selects, it always returns whatever was set as the default when the DropDownList was loaded.The DropDownList doesn't seem to react to SelectedIndexChanged either.
Private Sub ddlStates_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlStates.SelectedIndexChanged
MsgBox(ddlStates.Text)
End Sub
I'll admit it's been a while since I've done any programming, but I'm thinking it should work. So, what am I doing wrong?TIA
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry for the delay, but I had to go through some (unrelated) training.
Neither SelectedValue nor SelectedItem.Text worked.
As far as using the Page_Load event, this is (basically) what I have:
Neither SelectedValue nor SelectedItem.Text worked.
As far as using the Page_Load event, this is (basically) what I have:
loadDefaults() '<-- Sets g_sCurrentState to "North Carolina", among other presets
If Not IsPostBack Then
loadStateList()
If g_sCurrentState.Trim <> "" Then
ddlStates.Text = g_sCurrentState
End If
Else
g_sCurrentStateID = ViewState("StateID")
g_sCurrentState = ViewState("State")
loadStateList()
If g_sCurrentState <> "" Then
ddlStates.Text = g_sCurrentState
End If
End If
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It depends on whether its a postback.
On a fresh page, the value in "g_sCurrentState" is a system default value (basically a starter value).
On a page that has been posted back, "g_sCurrentState" is set to a ViewState value which should have been set during the ddlStates.SelectedIndexCha nged() event.
I just checked to make sure that is what my code was supposed to do. During testing, however, I find that the SelectedIndexChanged() event doesn't fire when you select a different State than the current one.
I also have a "Save" button, which currently does nothing more than display a messagebox with the ddlStates' value. It appears that, when I click on this button, the SelectedIndexChanged() event is fired (but still retains it's original value).
On a fresh page, the value in "g_sCurrentState" is a system default value (basically a starter value).
On a page that has been posted back, "g_sCurrentState" is set to a ViewState value which should have been set during the ddlStates.SelectedIndexCha
I just checked to make sure that is what my code was supposed to do. During testing, however, I find that the SelectedIndexChanged() event doesn't fire when you select a different State than the current one.
I also have a "Save" button, which currently does nothing more than display a messagebox with the ddlStates' value. It appears that, when I click on this button, the SelectedIndexChanged() event is fired (but still retains it's original value).
ASKER
Just letting y'all know I haven't abandoned this question. :-)