2009年9月7日   星期一   风晴   愉悦   隐私度(0)   
今天亲自写了一个ASP+数据库的省市区五级联动菜单!-mmxhero|邱少日记|邱少网|邱少时空站今天亲自写了一个ASP+数据库的省市区五级联动菜单!



<%
Function MyArea(rsProvince,rsCity,rsCounty,rsTown,rsStreet) '地区5级联动分类省市县镇村
Self=Request.ServerVariables("Script_Name")
if Request("Province")="" then
 Province=rsProvince
else
 Province=cint(Request("Province"))
end if

if Request("City")="" then
 City=rsCity
else
 City=cint(Request("City"))
end if
if Request("County")="" then
 County=rsCounty
else
 County=cint(Request("County"))
end if
if Request("Town")="" then
 Town=rsTown
else
 Town=cint(Request("Town"))
end if
if Request("Street")="" then
 Street=rsStreet
else
 Street=cint(Request("Street"))
end if
%>
<script language="javascript">
<!--
function changeDir1(Province){
location.assign("<%=Self%>?Act=<%=Act%>&SiteID=<%=SiteID%>&DirID=<%=DirID%>&ParentID=<%=ParentID%>&RootID=<%=RootID%>&Province=" + Province);
}

function changeDir2(City){
location.assign("<%=Self%>?Act=<%=Act%>&SiteID=<%=SiteID%>&DirID=<%=DirID%>&ParentID=<%=ParentID%>&RootID=<%=RootID%>&Province=<%=Province%>&City=" + City);
}

function changeDir3(County){
location.assign("<%=Self%>?Act=<%=Act%>&SiteID=<%=SiteID%>&DirID=<%=DirID%>&ParentID=<%=ParentID%>&RootID=<%=RootID%>&Province=<%=Province%>&City=<%=City%>&County=" + County);
}

function changeDir4(Town){
location.assign("<%=Self%>?Act=<%=Act%>&SiteID=<%=SiteID%>&DirID=<%=DirID%>&DirID=<%=DirID%>&ParentID=<%=ParentID%>&RootID=<%=RootID%>&Province=<%=Province%>&City=<%=City%>&County=<%=County%>&Town=" + Town);
}
-->
</script>

<select name="Province" onchange="changeDir1(this.value)">
<%
set rsTemp=server.createobject("adodb.recordset")
sql = "select * from  DirArea where RootID=1 and ParentID=0" '1类列表
rsTemp.open sql,conn,1,1 %><option value="">--请选择省市--</option>
<%do while not rsTemp.eof%>
 <%if Province=rsTemp("DirID") then%>
  <option value="<%=rsTemp("DirID")%>" selected><%=rsTemp("DirName")%></option>
 <%else%>
  <option value="<%=rsTemp("DirID")%>"><%=rsTemp("DirName")%></option>
 <%end if%>
<%rsTemp.movenext
loop
rsTemp.close
set rsTemp=nothing
%>
</select>

<select  name="City" onchange="changeDir2(this.value)">
<%if Province>0 then%>
 <%set rsTemp=server.createobject("adodb.recordset")
sql = "select * from  DirArea where RootID=2 and (ParentID="&Province&" ) " '2类列表
rsTemp.open sql,conn,1,1 %><option value="">--请选择地市--</option>
<%do while not rsTemp.eof%>
 <%if City=rsTemp("DirID")  then%>
  <option value="<%=rsTemp("DirID")%>" selected><%=rsTemp("DirName")%></option>
 <%else%>
  <option value="<%=rsTemp("DirID")%>"><%=rsTemp("DirName")%></option>
 <%end if%>
<%rsTemp.movenext
loop
rsTemp.close
set rsTemp=nothing%>
<%end if%>
</select>

<select name="County" onchange="changeDir3(this.value)">
<%if City>0 then%>
 <%set rsTemp=server.createobject("adodb.recordset")
sql = "select * from  DirArea where RootID=3 and ParentID="&City&" " '3类列表
rsTemp.open sql,conn,1,1 %><option value="">--请选择县市--</option>
<%do while not rsTemp.eof%>
 <%if County=rsTemp("DirID") then%>
  <option value="<%=rsTemp("DirID")%>" selected><%=rsTemp("DirName")%></option>
 <%else%>
  <option value="<%=rsTemp("DirID")%>"><%=rsTemp("DirName")%></option>
 <%end if%>
<%rsTemp.movenext
loop
rsTemp.close
set rsTemp=nothing%>
<%end if%>
</select>

<select name="Town" onchange="changeDir4(this.value)">
<%if County>0 then%>
 <%set rsTemp=server.createobject("adodb.recordset")
sql = "select * from  DirArea where RootID=4 and ParentID="&County&" " '4类列表
rsTemp.open sql,conn,1,1 %><option value="">--请选择乡镇--</option>
<%do while not rsTemp.eof%>
 <%if Town=rsTemp("DirID") then%>
  <option value="<%=rsTemp("DirID")%>" selected><%=rsTemp("DirName")%></option>
 <%else%>
  <option value="<%=rsTemp("DirID")%>"><%=rsTemp("DirName")%></option>
 <%end if%>
<%rsTemp.movenext
loop
rsTemp.close
set rsTemp=nothing%>
<%end if%>
</select>

<select name="Street">
<%if Town>0 then%>
 <%set rsTemp=server.createobject("adodb.recordset")
sql = "select * from  DirArea where RootID=5 and ParentID="&Town&" " '4类列表
rsTemp.open sql,conn,1,1 %><option value="">--请选择省街村--</option>
<%do while not rsTemp.eof%>
 <%if Street=rsTemp("DirID") then%>
  <option value="<%=rsTemp("DirID")%>" selected><%=rsTemp("DirName")%></option>
 <%else%>
  <option value="<%=rsTemp("DirID")%>"><%=rsTemp("DirName")%></option>
 <%end if%>
<%rsTemp.movenext
loop
rsTemp.close
set rsTemp=nothing%>
<%end if%>
</select>
<%End Function%>







ASP应用添加新记录:
<%=MyArea(0,0,0,0,0)%>




ASP应用修改记录:
<%=MyArea(rs("Province"),rs("City"),rs("County"),rs("Town"),rs("Street"))%>





建立SQL数据库:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DirArea]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[DirArea]
GO


CREATE TABLE [dbo].[DirArea] (
 [DirID] [int] IDENTITY (1, 1) NOT NULL ,
 [ParentID] [int] NOT NULL ,
 [RootID] [int] NOT NULL ,
 [DirName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO


 
mmxhero 写于 北京市东城区鼓楼大街安德路55号13栋105室  

 

网友的评论意见或建议
还没有评论!
欢迎
参与
评论
您尚未登录网站,欢迎发表评论或留下意见建议,注册成为本站会员。
 
 
最近来访的网友

18.207.134.98

159.69.186.191

46.229.168.139

220.181.125.158

216.244.66.241

54.36.148.48

204.12.220.106

42.236.54.42

42.236.99.206

5.9.98.130

54.36.148.119

46.229.168.138

42.236.10.81

110.249.201.162

46.229.168.131

106.47.30.254

54.36.148.133

111.224.6.185

123.191.132.209

116.55.182.116
邱少网 ©1998-2019 神族网络信息分享无限公司|个人公益事业非经营网站
站长邮箱:mmxhero@163.com    站长QQ:156369596  
【最近访客=136 】  
mmxhero(M8,N0) 故事与酒清风与你(M1,N0) sgsddszy123(M1,N0) sgsddszy(M2,N0) PandaGuoxue(M1,N0) sd17173(M1,N0)
mashaojun(M1,N3) 321456987(M1,N0) xutanyuan(M3,N0) outoTinfo(M1,N0)