1个回答
展开全部
我给你一个三级联动的程序,根据我这个程序你自己修改代码。比如有一个表,名称为:人员表
id 学校 班级 姓名
1 中学 一班 王一
2 中学 三班 孙二
3 高中 二班 张三
你现在第一级选择是学校,第二级是班级
本页面为chaxun.asp
<%
'此处加连接数据库语句省略
set conn=......
conn.open "...... "
sql= "select distinct 学校 from 人员表 "
set rs=conn.execute(sql)%>
<form id= "form1 " name= "form1 " method= "post " action= "chaxun.asp ">
<table width= "600 " border= "1 ">
<tr>
<td width= "179 "> <div align= "center "> 学校 </div> </td>
<td width= "405 ">
<select name= "xuexiao " id= "xuexiao " onchange= "chaxun.asp?xx= '+this.value ">
<option value= " "> ==请选择学校== </option>
<%
if not rs.eof and not rs.bof then
do while not rs.eof%>
<option value= " <%=rs( "学校 ")%> " <%if trim(rs( "学校 "))=trim(request( "xx ")) then%> selected <%end if%> > <%=rs( "学校 ")%> </option>
<%rs.movenext
loop
end if%>
</select>
</td>
</tr>
<tr>
<td> <div align= "center "> 班级 </div> </td>
<td> <select name= "banji " id= "banji " onchange= "chaxun.asp?xx= <%=request( "xx ")%> &bj= '+this.value ">
<option value= " "> ==请选择班级== </option>
<%if request( "xx ") <> " " then
sql= "select distinct 班级 from 人员表 where 学校= ' "&request( "xx ")& " ' "
set rs1=conn.execute(sql)
if not rs1.eof and not rs1.bof then
do while not rs1.eof%>
<option value= " <%=rs1( "班级 ")%> " <%if trim(rs1( "班级 "))=trim(request( "bj ")) then%> selected <%end if%> > <%=rs( "班级 ")%> </option>
<%rs1.movenext
loop
end if
end if%>
</select> </td>
</tr>
<tr>
<td> <div align= "center "> 姓名 </div> </td>
<td> <select name= "name " id= "name " onchange= "chaxun.asp?xx= <%=request( "xx ")%> &bj= <%=request( "bj ")%> &name= '+this.value ">
<option value= " "> ==请选择人员== </option>
<%if request( "xx ") <> " " and reqeust( "bj ") <> " " then
sql= "select 姓名 from 人员表 where 学校= ' "&request( "xx ")& " ' and 班级= ' "&request( "bj ")& " ' "
set rs2=conn.execute(sql)
if not rs2.eof and not rs2.bof then
do while not rs2.eof%>
<option value= " <%=rs2( "姓名 ")%> " <%if trim(rs2( "姓名 "))=trim(request( "name ")) then%> selected <%end if%> > <%=rs2( "姓名 ")%> </option>
<%rs2.movenext
loop
end if
end if%>
</select> </td>
</tr>
</table>
</form>
<%set conn=nothing%>
具体没有测试,你试试看,不行再问我
id 学校 班级 姓名
1 中学 一班 王一
2 中学 三班 孙二
3 高中 二班 张三
你现在第一级选择是学校,第二级是班级
本页面为chaxun.asp
<%
'此处加连接数据库语句省略
set conn=......
conn.open "...... "
sql= "select distinct 学校 from 人员表 "
set rs=conn.execute(sql)%>
<form id= "form1 " name= "form1 " method= "post " action= "chaxun.asp ">
<table width= "600 " border= "1 ">
<tr>
<td width= "179 "> <div align= "center "> 学校 </div> </td>
<td width= "405 ">
<select name= "xuexiao " id= "xuexiao " onchange= "chaxun.asp?xx= '+this.value ">
<option value= " "> ==请选择学校== </option>
<%
if not rs.eof and not rs.bof then
do while not rs.eof%>
<option value= " <%=rs( "学校 ")%> " <%if trim(rs( "学校 "))=trim(request( "xx ")) then%> selected <%end if%> > <%=rs( "学校 ")%> </option>
<%rs.movenext
loop
end if%>
</select>
</td>
</tr>
<tr>
<td> <div align= "center "> 班级 </div> </td>
<td> <select name= "banji " id= "banji " onchange= "chaxun.asp?xx= <%=request( "xx ")%> &bj= '+this.value ">
<option value= " "> ==请选择班级== </option>
<%if request( "xx ") <> " " then
sql= "select distinct 班级 from 人员表 where 学校= ' "&request( "xx ")& " ' "
set rs1=conn.execute(sql)
if not rs1.eof and not rs1.bof then
do while not rs1.eof%>
<option value= " <%=rs1( "班级 ")%> " <%if trim(rs1( "班级 "))=trim(request( "bj ")) then%> selected <%end if%> > <%=rs( "班级 ")%> </option>
<%rs1.movenext
loop
end if
end if%>
</select> </td>
</tr>
<tr>
<td> <div align= "center "> 姓名 </div> </td>
<td> <select name= "name " id= "name " onchange= "chaxun.asp?xx= <%=request( "xx ")%> &bj= <%=request( "bj ")%> &name= '+this.value ">
<option value= " "> ==请选择人员== </option>
<%if request( "xx ") <> " " and reqeust( "bj ") <> " " then
sql= "select 姓名 from 人员表 where 学校= ' "&request( "xx ")& " ' and 班级= ' "&request( "bj ")& " ' "
set rs2=conn.execute(sql)
if not rs2.eof and not rs2.bof then
do while not rs2.eof%>
<option value= " <%=rs2( "姓名 ")%> " <%if trim(rs2( "姓名 "))=trim(request( "name ")) then%> selected <%end if%> > <%=rs2( "姓名 ")%> </option>
<%rs2.movenext
loop
end if
end if%>
</select> </td>
</tr>
</table>
</form>
<%set conn=nothing%>
具体没有测试,你试试看,不行再问我
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询