Hi all,
I have two dropdownlist (country and city dropdownlists) taking their data from access database, in order for filtering the data shown in gridview.
I want city dropdownlist get notified and change whenever a country selected from country dropdown list
I mean, wheneever user selects a country, I want city dropdownlist to show only cities only from the selected country
Right now I only use ASP NET (behind code),
In order to make that dynamic dropdownlist, do I hav to write c# code ?
can someone show how cna I do it with ASP NEt or c#?
Thanks!
And here is my full ASP NET code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<title>Untitled Page</title>
<link rel="stylesheet" type="text/css" href="gridview.css" media="all" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<h3>Gridview with Filtering</h3>
<div class="GridviewDiv">
<table style="width: 540px" border="0" cellpadding="0" cellspacing="1" class="GridviewTable">
<tr >
<td onmouseover="this.style.background='red';this.style.cursor='pointer'"
onmouseout="this.style.background='orange';" onclick="City='http://www.google.com'">
ID </td>
<td style="width: 120px;" >
First Name
</td>
<td style="width: 120px;">
Last Name
</td>
<td style="width: 130px;">
Country
</td>
<td style="width: 130px;">
City
</td>
</tr>
<tr >
<td style="width: 40px;" >
</td>
<td style="width: 120px;">
</td>
<td style="width: 130px;">
</td>
<td style="width: 130px;">
<asp:DropDownList ID="ddlCountry" runat="server" AppendDataBoundItems="true"
AutoPostBack="true" DataSourceID="dsPopulateCountry"
DataValueField="Country" Font-Size="11px" Height="16px" Width="120px">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
</td>
<td style="width: 130px;">
<asp:DropDownList ID="ddlCity" runat="server" AppendDataBoundItems="true"
AutoPostBack="true" DataSourceID="dsPopulateCity" DataValueField="City"
Font-Size="11px" Width="120px">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="5">
<asp:GridView
ID="Gridview1"
runat="server"
AutoGenerateColumns="False"
AllowPaging="True"
AllowSorting="true"
DataSourceID="dsGridview"
Width="540px"
PageSize="10"
CssClass="Gridview"
onrowdatabound="gdvPeople_RowDataBound">
<Columns>
<asp:hyperlinkfield headertext="Title"
datatextfield="id"
datanavigateurlformatstring="title_details.aspx?titleid={0}"
datanavigateurlfields="id" />
<asp:BoundField DataField="id" HeaderText="Sırala" SortExpression="id" ItemStyle-Width="40px"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="FirstName" HeaderText="Sırala" SortExpression="FirstName"
ItemStyle-Width="120px" />
<asp:BoundField DataField="LastName" HeaderText="Sırala" SortExpression="LastName"
ItemStyle-Width="120px" />
<asp:BoundField DataField="Country" HeaderText="Sırala" SortExpression="Country"
ItemStyle-Width="130px" />
<asp:BoundField DataField="City" HeaderText="Sırala" SortExpression="City"
ItemStyle-Width="130px" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
<asp:AccessDataSource ID="dsGridview" runat="server" DataSourceMode="DataSet"
DataFile="Database2.mdb"
SelectCommand="SELECT * FROM T_Employees"
FilterExpression="Country like '{0}%' and City like '{1}%' ">
<FilterParameters>
<asp:ControlParameter Name="Country" ControlID="ddlCountry" PropertyName="SelectedValue" />
<asp:ControlParameter Name="City" ControlID="ddlCity" PropertyName="SelectedValue" />
</FilterParameters>
</asp:AccessDataSource>
<asp:AccessDataSource ID="dsPopulateCountry" runat="server" DataFile="Database2.mdb"
SelectCommand="SELECT DISTINCT Country from T_Employees"></asp:AccessDataSource>
<asp:AccessDataSource ID="dsPopulateCity" runat="server" DataFile="Database2.mdb"
SelectCommand="SELECT DISTINCT City FROM T_Employees"></asp:AccessDataSource>
<asp:AccessDataSource ID="dsPopulateFirstName" runat="server" DataFile="Database2.mdb"
SelectCommand="SELECT DISTINCT FirstName FROM T_Employees"></asp:AccessDataSource>
<asp:AccessDataSource ID="dsPopulateLastName" runat="server" DataFile="Database2.mdb"
SelectCommand="SELECT DISTINCT LastName FROM T_Employees"></asp:AccessDataSource>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>