Question about querystring

J

JenHu

In my restaurant.aspx, I have a 2 dropdownlists (ddlState, ddlCity)
and a button (btnFindRestaurants). The 2 dropdownlist has the first
item as "--Choose--"

After user selected a state and a city and clicked the
btnfindrestaruants button, it should redirect to storelist.aspx page
by using querystrings and list all the restaurants belongs to the
selected State and city.

However, after user selected the state and city, and clicked the
button, the querystring only carries State, I found city is passed
the value "--Choose--" at runtime ( City =
Request.QueryString("City")) but city is picked by user other than
the "--Choose--".

Here is my code, can someone please tell me why I can't get the
selecte value from the City dropdownlist? Thank you.

In restaurant.aspx
------------------------------------
Private Sub btnFindRestaurants_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnFindRestaurants.Click

Response.Redirect("storelist.aspx?City=" + ddlCity.SelectedItem.Text +
"&State=" + ddlState.SelectedItem.Text, True)

End Sub
------------------------------------

In storelist.aspx

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim State As String
Dim City As String
Dim ds As DataSet
Dim dr As SqlDataReader
State = Request.QueryString("State")
City = Request.QueryString("City")
conDWDb.Open()
Dim cmdCountStores As New SqlCommand
Dim dtrCountStores As SqlDataReader
With cmdCountStores
.Connection = conDWDb
.CommandText = "Select Count(*) As CountStores from store_table where
co_code=1 and store_mgr is not null and State=@State and City=@City"

.Parameters.Add("@State", SqlDbType.Char).Value = State
.Parameters.Add("@City", SqlDbType.Char).Value = City
End With
dtrCountStores = cmdCountStores.ExecuteReader
dtrCountStores.Read()
lblnumber.Text = dtrCountStores("CountStores")
dtrCountStores.Close()
conDWDb.Close()
End If
End Sub
 
2

2kool

My guess would be that you are re-binding the dropdownlist in
restaurant.aspx before the SelectedItem property is accessed in
btnFindRestaurants_Click.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top