Step 1: Create a table in database
create table test
(
state1 varchar(50),
city varchar(50)
)
Step 2: In the .aspx Page
<select id="statelist" runat="server" onchange="showCity()" style="width: 160px">
<option></option>
</select>
<asp:DropDownList ID="citylist" runat="server" Width="184px">
</asp:DropDownList>
Take statelist for State and citylist for City
When you select any item from statelist the citylist will automatically fill because of ajax
Step 3: Write this in the <head> Part
<script language="JavaScript"
type="text/javascript"
>
var xmlHttp
var arr;
function
showCity() {
xmlHttp = GetXmlHttpObject()
var url
= "Default.aspx"
url = url + "?name="
+ document.getElementById('statelist').value
xmlHttp.onreadystatechange =
stateChanged
xmlHttp.open("GET",
url, true)
xmlHttp.send(null)
return false;
}
function
stateChanged() {
if
(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
{
var
str;
str = xmlHttp.responseText;
arr = str.split(",");
var
i;
for
(i = 0; i < arr.length; i++) {
dd2 = document.getElementById("citylist")
var
theOption = new Option;
theOption.text = arr[i];
theOption.value = arr[i];
dd2.options[i] = theOption;
}
}
}
function
GetXmlHttpObject() {
var
objXMLHttp = null

Satyapriya NayakPosted Dec 9, 2010, 7:53 AM
Its working fine. Thanks