vb - querystringparameter and masterpage

Jul 13, 2009
Reaction score
I am creating a website where the search parameters state, city and county are in the masterpage file using dropdownlists. I am trying to have the search parameters on each page. The search results are not in the master page they are in a page called searchresults.aspx. So if someone is at the home page they can select state, city and county and then click submit. It will redirect them to the searchresults page where it should show the results however it is not working. The page will load but there are no results. However, once at the searchresults page, if you enter the state, county and city again it does show the results. I did try to see if I could get the values from the dropdownlists to load into a label and it would do the same thing. Any help would be great. My code is below. Thank you.

Code from MasterPage

<asp:DropDownList ID="lstState" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="State"
<asp:ListItem Value="-1">Choose State</asp:ListItem>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT [State] FROM
ORDER BY [State]">
<asp:DropDownList ID="lstCounty" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="County"
<asp:ListItem Value="-1">Choose County</asp:ListItem>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

SelectCommand="SELECT DISTINCT [County] FROM
WHERE ([State] = @State) ORDER BY [County]">
<asp:ControlParameter ControlID="lstState" Name="State"
PropertyName="SelectedValue" Type="String" />
<asp:DropDownList ID="lstCity" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="City"
<asp:ListItem Value="-1">Choose City</asp:ListItem>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

SelectCommand="SELECT DISTINCT [City] FROM
WHERE ([County] = @County)">
<asp:ControlParameter ControlID="lstCounty" Name="County"
PropertyName="SelectedValue" Type="String" />
<asp:Button ID="cmdSubmit" runat="server" Text="Button"
PostBackUrl="~/Search/SearchResults.aspx" />

Code Behind from MasterPage:

Response.Redirect("SearchResults.aspx?State=" & lstState.SelectedValue & "&County=" & lstCounty.SelectedValue & "&City=" & lstCity.SelectedValue )

Code from SearchResults:

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource5"
AutoGenerateColumns="False" DataKeyNames="Id">
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="UserID" HeaderText="UserID"
SortExpression="UserID" />
<asp:BoundField DataField="Title" HeaderText="AdTitle"
SortExpression="AdTitle" />
<asp:BoundField DataField="Description" HeaderText="AdDescription"
SortExpression="AdDescription" />
<asp:BoundField DataField="AdTypeID" HeaderText="Type"
SortExpression="AdTypeID" />
<asp:BoundField DataField="AdStartDate" HeaderText="StartDate"
SortExpression="AdStartDate" />
<asp:BoundField DataField="AdEndDate" HeaderText="EndDate"
SortExpression="AdEndDate" />
<asp:BoundField DataField="PaidAd" HeaderText="Paid"
SortExpression="PaidAd" />
<asp:BoundField DataField="ZipCode" HeaderText="ZipCode"
SortExpression="ZipCode" />
<asp:BoundField DataField="PicID" HeaderText="PicID" SortExpression="PicID" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="County" HeaderText="County"
SortExpression="County" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="AdCategory" HeaderText="Category"
SortExpression="AdCategory" />
<asp:SqlDataSource ID="SqlDataSource5" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

SelectCommand="SELECT * FROM
WHERE (([State] = @State) AND ([County] = @County) AND ([City] = @City)) ORDER BY [Id]">
<asp:QueryStringParameter QueryStringField="State" Name="State" Type="String" />
<asp:QueryStringParameter QueryStringField="County" Name="County" Type="String" DefaultValue="adCounty"/>
<asp:QueryStringParameter QueryStringField="City" Name="City" Type="String" DefaultValue="adCity"/>


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