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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bind dropdown values to SQLdatasource select statement

Status
Not open for further replies.

quwesi

Programmer
May 2, 2008
5
On the same page I have
1. a cascading dropdown of 2 dropdowns to select state/province and then city
2. Sqldatasource to select data from a database, depending on the values chosen in the dropdowns and
3. a gridview to display the the results of the selection.

However, when I choose the state and the city nothing happens.

I need help to wire together the dropdowns and the sqldatasource so that when a city is chosen
the sqldatasource will be triggered and then the gridview displays the selected rows.


below is my code:


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" EnableEventValidation="false" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns="
<head runat="server">

<title>Untitled Page</title>


<script type="text/javascript">


function pageLoad() {

}


</script>


<style type="text/css">

.style1

{

width: 357px;

}

.style5

{

width: 139px;

}

.style6

{

width: 142px;

}

</style>

</head>

<body>

<form id="form1" runat="server">


<div style="height: 26px">

<asp:ScriptManager ID="ScriptManager1" runat="server" />

</div>


<div style="height: 140px">

<br />

<br />

<table cellpadding="2" cellspacing="1" class="style1">

<tr>

<td class="style5">

Province:</td>

<td class="style6">

City:</td>

</tr>

<tr>

<td class="style5">

<asp:DropDownList ID="ddlProvince" runat="server" Width="180px">

</asp:DropDownList>

</td>

<td class="style6">

<asp:DropDownList ID="ddlCity" runat="server" Width="180px">

</asp:DropDownList>

</td>

</tr>

</table>


<br />

<br />

<cc1:CascadingDropDown

ID="cddProvince"

runat="server"

TargetControlID="ddlProvince"

Category="Province"

PromptText="Select a province"

ServicePath="Location.asmx"

ServiceMethod="GetProvince" LoadingText="loading data..." />

<br />

<cc1:CascadingDropDown

ID="cddCity"

runat="server"

TargetControlID="ddlCity"

ParentControlID="ddlProvince"

Category="City"

PromptText="Select a city"

ServicePath="Location.asmx"

ServiceMethod="GetCity" LoadingText="loading data..." />


<br />

&nbsp;</div>

<p style="height: 61px">

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStringslaceConnectionString1 %>"

SelectCommand="SELECT [cityName], [ownerName], [ownerPhone], [numOfRooms], [rent], [listPeriod], [addInfo] FROM [Property] WHERE (([cityName] = @cityName) AND ([provinceName] = @provinceName))">

<SelectParameters>

<asp:ControlParameter ControlID="ddlCity" Name="cityName"

PropertyName="SelectedValue" Type="String" />

<asp:ControlParameter ControlID="ddlProvince" Name="provinceName"

PropertyName="SelectedValue" Type="String" />

</SelectParameters>

</asp:SqlDataSource>

</p>

<p style="height: 207px">

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundField DataField="cityName" HeaderText="cityName"

SortExpression="cityName" />

<asp:BoundField DataField="ownerName" HeaderText="ownerName"

SortExpression="ownerName" />

<asp:BoundField DataField="ownerPhone" HeaderText="ownerPhone"

SortExpression="ownerPhone" />

<asp:BoundField DataField="numOfRooms" HeaderText="numOfRooms"

SortExpression="numOfRooms" />

<asp:BoundField DataField="rent" HeaderText="rent" SortExpression="rent" />

<asp:BoundField DataField="listPeriod" HeaderText="listPeriod"

SortExpression="listPeriod" />

<asp:BoundField DataField="addInfo" HeaderText="addInfo"

SortExpression="addInfo" />

</Columns>

</asp:GridView>

</p>

<p style="height: 207px">

&nbsp;</p>

</form>

</body>

</html>
 
looks like your using MS Ajax Control Toolkit. you need a static pagemethod to load the dropdowns, I don't think you can use the sqldatasource. follow the example on the ajax control toolkit sample application. Note: you also need to disable viewstate validation for this to work.

if you want to use sqldatasource you will need to use an updatepanel and set the 1st dropdown to autopostback. this will not require you to disable viewstate validation. again this is documented in the control toolkit sample app.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top