Hi,
I can't get the OnSelectedIndexChanged event to fire on a dropdownlist control.
Here is how my page is designed:
When my page loads, I have a dropdownlist with a list of states. When the user changes the dropdownlist, the AutoPostBack fires and runs a sub that loads & shows a second dropdownlist that shows cities for the state selected.
The problem occurs when I make a selection from the city dropdownlist. Nothing happens.
Here is my dropdownlist:
<form runat="server">
<asp
ropDownList ID="drpCityList" onfiltered="GetATMList" runat="server">
</asp
ropDownList>
</form>
Here is the code in a codebehind page:
Public Sub GetATMList(sender As Object, e As System.EventArgs)
'This sub loads the ATM's for the city selected.
Dim objConn As SqlConnection
Dim objSQLCommand As SqlCommand
Dim objDataReader as SqlDataReader
Dim strCity as String = drpCityList.SelectedItem.Text
if UCase(strCity) <> "NOW SELECT A CITY" then
'Set up our connection object and SQL command object.
objConn = New SqlConnection(application("WSFSQLConnString"
)
objSQLCommand = New SqlCommand("AD_s_GetATMByCity", objConn)
'Set the stored procedure.
objSQLCommand.CommandType = CommandType.StoredProcedure
'Add parameters.
objSQLCommand.Parameters.Add("@City", strCity)
'Open the db connection & Execute Command
objConn.Open()
'Execute the procedure.
objDataReader = objSQLCommand.ExecuteReader()
'Now bind the datareader to the repeater.
grdATMs.DataSource = objDataReader
grdATMs.DataBind()
'Close the DB connection.
objConn.Close()
end if
end Sub 'GetATMList
I tried to change the sub to set the value to a label, thinking maybe there was something wrong with the value of the dropdownlist. But it didn't work either.
What am I doing wrong?
Thanks,
Mark
I can't get the OnSelectedIndexChanged event to fire on a dropdownlist control.
Here is how my page is designed:
When my page loads, I have a dropdownlist with a list of states. When the user changes the dropdownlist, the AutoPostBack fires and runs a sub that loads & shows a second dropdownlist that shows cities for the state selected.
The problem occurs when I make a selection from the city dropdownlist. Nothing happens.
Here is my dropdownlist:
<form runat="server">
<asp
</asp
</form>
Here is the code in a codebehind page:
Public Sub GetATMList(sender As Object, e As System.EventArgs)
'This sub loads the ATM's for the city selected.
Dim objConn As SqlConnection
Dim objSQLCommand As SqlCommand
Dim objDataReader as SqlDataReader
Dim strCity as String = drpCityList.SelectedItem.Text
if UCase(strCity) <> "NOW SELECT A CITY" then
'Set up our connection object and SQL command object.
objConn = New SqlConnection(application("WSFSQLConnString"
objSQLCommand = New SqlCommand("AD_s_GetATMByCity", objConn)
'Set the stored procedure.
objSQLCommand.CommandType = CommandType.StoredProcedure
'Add parameters.
objSQLCommand.Parameters.Add("@City", strCity)
'Open the db connection & Execute Command
objConn.Open()
'Execute the procedure.
objDataReader = objSQLCommand.ExecuteReader()
'Now bind the datareader to the repeater.
grdATMs.DataSource = objDataReader
grdATMs.DataBind()
'Close the DB connection.
objConn.Close()
end if
end Sub 'GetATMList
I tried to change the sub to set the value to a label, thinking maybe there was something wrong with the value of the dropdownlist. But it didn't work either.
What am I doing wrong?
Thanks,
Mark