| View previous topic :: View next topic |
| Author |
Message |
Jubeda
Joined: 30 Aug 2007 Posts: 6
|
Posted: Thu Aug 30, 2007 10:32 am Post subject: How to populate items to dropdown in ASP.NET using AJAX |
|
|
Hi,
How to populate the items to the dropdown and when changing the
item in the first dropdown box the corresponding items must be display
in the second dropdown.can anybody send a sample script. |
|
| Back to top |
|
 |
Abhi
Joined: 21 Aug 2007 Posts: 145
|
Posted: Thu Aug 30, 2007 10:53 am Post subject: |
|
|
Hi jubeda,
I think the following code will be helpful to u.I took one database file
cities.mdb. In one dropdown i populated the states of us.In another dropdown i populated the corresponding state cities.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax_DDL_Cities.aspx.cs" Inherits="Default2" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!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 runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:UpdateProgress id="UpdateProgress1" runat="server" AssociatedUpdatePanelID ="UpdatePanel1">
<progresstemplate>
</progresstemplate>
</asp:UpdateProgress>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel id="UpdatePanel1" runat="server">
<contenttemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="AccessDataSource1" AutoPostBack="true"
DataTextField="State" DataValueField="State" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="AccessDataSource2"
DataTextField="City" DataValueField="City">
</asp:DropDownList>
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/cities.mdb"
SelectCommand="SELECT Distinct [City] FROM [Commercial] Where state=@stateid">
<SelectParameters >
<asp:ControlParameter Name =stateid ControlID ="DropDownList1"/>
</SelectParameters>
</asp:AccessDataSource>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/cities.mdb"
SelectCommand="SELECT DISTINCT [State] FROM [Commercial]">
</asp:AccessDataSource>
</contenttemplate>
</asp:UpdatePanel>
</form>
</body>
</html> |
|
| Back to top |
|
 |
|