注册 登录
编程论坛 ASP技术论坛

如何动态根据 select 控件中的内容进行 显示

afliult 发布于 2007-09-09 21:53, 989 次点击

下面是我写ASP 程序时所碰到的一个问题:
我想选择男,那么就只显示性别为男的学生,
如果选择女,那么就只显示性别为女的学生,
下面的代码为什么实现不了,请各位大师指教


<!--#include file="conn.asp"-->

<html>
<head>
<title> 学生情况表登记 </title>
</head>

<script language=javascript>
function bao(s)
{
<%
session("this_sex")=s
%>
}
</script>

<body>

<form method="post" action="select02.asp">

<p align=center>

<select name=sel onchange="bao(this.options[this.options.selectedIndex].value)">
<option value="全部">全部
<option value="男" <% if session("this_sex")="男" then Response.write "selected" %> >男
<option value="女" <% if session("this_sex")="女" then Response.write "selected" %> >女
</select>

<input class="button" type="submit" name="Submit" value="确定">

</p>

<TABLE width="680" border=0 align="center" cellPadding=4 cellSpacing=1 bgcolor="#CCCCCC" class="table">
<tr align="center">
<td width="48" bgcolor="#f7f7f7">编号</td>
<td width="166" bgcolor="#f7f7f7">姓名</td>
<td width="130" bgcolor="#f7f7f7">性别</td>
<td width="180" bgcolor="#f7f7f7">家庭地址</td>
<td width="150" bgcolor="#f7f7f7">毕业学校</td>
</tr>

<%
dim rs,sql
set rs = server.createobject("adodb.recordset")

if session("this_sex")="" or session("this_sex")="全部" then
sql="select * from student"
end if

if session("this_sex")="男" then
sql="select * from student where sex='男'"
end if

if session("this_sex")="女" then
sql="select * from student where sex='女'"
end if

rs.open sql,conn,1,1

dim i
i=0
do while not rs.eof
%>
<tr align="center">
<td width="48" bgcolor="#f7f7f7"><%=i+1%></td>
<td width="166" bgcolor="#f7f7f7"><%=rs("name")%></td>
<td width="130" bgcolor="#f7f7f7"><%=rs("sex")%></td>
<td width="180" bgcolor="#f7f7f7"><%=rs("addr")%></td>
<td width="150" bgcolor="#f7f7f7"><%=rs("gradeby")%></td>
</tr>
<%
i=i+1
rs.movenext
loop

rs.close
%>
</table>
</form>
</body>
</html>

只有本站会员才能查看附件,请 登录

3 回复
#2
afliult2007-09-09 21:56
我把我的源码放在后面,请下载修改后,上传,谢谢!
希望能和各位大师交个朋友
QQ: 397437671
#3
hmhz2007-09-10 08:45

帮你修改好了,你看看

<!--#include file="conn.asp"-->

<html>
<head>
<title> 学生情况表登记 </title>
</head>

<body>
<%this_sex=request.form("sel")%>
<p align=center>
<form action="" method="post">
<select name="sel" onchange="this.form.submit()">
<option value="全部">全部
<option value="男"<%if this_sex="男" then%> selected<%end if%>>男
<option value="女"<%if this_sex="女" then%> selected<%end if%>>女
</select>
</form>
</p>

<TABLE width="680" border=0 align="center" cellPadding=4 cellSpacing=1 bgcolor="#CCCCCC" class="table">
<tr align="center">
<td width="48" bgcolor="#f7f7f7">编号</td>
<td width="166" bgcolor="#f7f7f7">姓名</td>
<td width="130" bgcolor="#f7f7f7">性别</td>
<td width="180" bgcolor="#f7f7f7">家庭地址</td>
<td width="150" bgcolor="#f7f7f7">毕业学校</td>
</tr>

<%
dim rs,sql
set rs = server.createobject("adodb.recordset")
if this_sex="" or this_sex="全部" then
rs.open "select name,sex,addr,gradeby from student",conn,1,1
else
rs.open "select name,sex,addr,gradeby from student where sex='"&this_sex&"'",conn,1,1
end if
set name=rs("name")
set sex=rs("sex")
set addr=rs("addr")
set gradeby=rs("gradeby")
i=0
do while not rs.eof
%>
<tr align="center" bgcolor="#f7f7f7">
<td width="48"><%=i+1%></td>
<td width="166"><%=name%></td>
<td width="130"><%=sex%></td>
<td width="180"><%=addr%></td>
<td width="150"><%=gradeby%></td>
</tr>
<%
i=i+1
rs.movenext
loop
rs.close
set rs=nothing
%>
</table>

</body>
</html>

[此贴子已经被作者于2007-9-10 8:51:21编辑过]

#4
afliult2007-09-10 09:32

谢谢这位大师,现在有用了

1