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">
<aspropDownList ID="ddlProvince" runat="server" Width="180px">
</aspropDownList>
</td>
<td class="style6">
<aspropDownList ID="ddlCity" runat="server" Width="180px">
</aspropDownList>
</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 />
</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">
</p>
</form>
</body>
</html>
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">
<aspropDownList ID="ddlProvince" runat="server" Width="180px">
</aspropDownList>
</td>
<td class="style6">
<aspropDownList ID="ddlCity" runat="server" Width="180px">
</aspropDownList>
</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 />
</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">
</p>
</form>
</body>
</html>