1创建三张页面main.aspx、callservershen.aspx、callservershi.aspx
在main.aspx页面中放两个下拉列表
<SELECT id="drp1" style="WIDTH: 112px" οnchange="LoadShi();">
<OPTION selected></OPTION>
</SELECT>
<SELECT id="drp2" style="WIDTH: 116px">
<OPTION selected></OPTION>
</SELECT>
然后写javascript
<
script
>
var
xmlhttp
=
false
;
var
DrpInfo
=
""
;
function
GetXmlHttp()
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
if(window.ActiveXObject)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP.3.0");
}
catch(e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
}
}
}
return xmlhttp;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
************************** 窗 体 加 载 ----- 省 ***************************
function
LoadShen()
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
GetXmlHttp();
var url="callservershen.aspx";
xmlhttp.onreadystatechange=ReadStateShen;
xmlhttp.open("post",url,true);
xmlhttp.send();
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
function
ReadStateShen()
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
var drp1=document.getElementById("drp1");
if(xmlhttp.readyState==1)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
DrpInfo="数据加载中..";
drp1.options[0]=new Option(DrpInfo,DrpInfo);
}
if(xmlhttp.reaydState==4)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
document.getElementById("drp1").length=0;
drp1.options[0]=new Option("请选择");
var msg=xmlhttp.responseText;
msg=msg.substring(0,msg.length-1);
var msgarray=new Array();
msgarray=msg.split(",");
for(var i=0;i<msgarray.length;i++)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
DrpInfo=msgarray[i];
drp1.options[drp1.length]=new Option(DrpInfo,DrpInfo);
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
************************** 根 据 选 择 的 省 加 载 市 ***************************
function
LoadShi()
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
GetXmlHttp();
var drp1=document.getElementById("drp1");
var drpInfo=drp1.options[drp1.selectedIndex].text;
var url="callservershi.aspx?shi="+escape(drpInfo);
xmlhttp.onreadystatechange=ReadStateShi;
xmlhttp.open("post",url,true);
xmlhttp.send();
}
function
ReadStateShi()
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
var drp2=document.getElementById("drp2");
if(xmlhttp.readyState==1)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
DrpInfo="数据加载中..";
drp2.options[0]=new Option(DrpInfo);
}
if(xmlhttp.readyState==4)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
var msg=xmlhttp.responseText;
msg=msg.substring(0,msg.length-1);
var msgarray=new Array();
msgarray=msg.split(",");
for(var i=0;i<msgarray.length;i++)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
DrpInfo=msgarray[i];
drp2.options[drp2.length]=new Option(DrpInfo,DrpInfo);
}
}
}
</
script
>
2在callservershen.aspx页面的page_load写如下代码 (注:查出数据中所有省名)
SqlConnection conn
=
new
SqlConnection(
"
server=.;database=test;uid=aa;pwd=aa
"
);
private
void
Page_Load(
object
sender, System.EventArgs e)
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
if(!this.IsPostBack)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.Bind();
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
private
void
Bind()
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
string strSql="select distinct(shen) from city";
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter(strSql,conn);
da.Fill(ds,"dd");
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Response.Write(ds.Tables[0].Rows[i][0].ToString()+",");
}
Response.End();
}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
catch(Exception)...{}
}
3在callservershi.aspx页面的page_load写如下代码 (注:查出数据中所有市名)
SqlConnection conn
=
new
SqlConnection(
"
server=.;database=test;uid=aa;pwd=aa
"
);
private
void
Page_Load(
object
sender, System.EventArgs e)
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
if(!this.IsPostBack)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.Bind();
}
}
private
void
Bind()
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
string str=Request.QueryString["shi"].ToString();
string strSql="select shi from city where shen='"+str+"'";
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter(strSql,conn);
da.Fill(ds,"dd");
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Response.Write(ds.Tables[0].Rows[i][0].ToString()+",");
}
Response.End();
}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
catch(Exception )...{}
}
4在main.aspx页面中的<body>标签写οnlοad="LoadShen();"
<body οnlοad="LoadShen();">