我想在这里做的是根据组合框中选择的选项加载图片。但是当我在页面重新加载后从组合框中选择“2011”时,所选的选项再次是2012.plz帮助我.... 这是我的ASP代码
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><
<head><title>Sinhgad Alumni</title>
<script type="text/javascript"></script>
</head>
<link rel="stylesheet" type="text/css" href="theme/gallery.css">
<body>
<%dim conn,rs,alumniyear,rs2
Response.write(alumniyear)
Set conn=Server.createObject("ADODB.Connection")
Set rs=Server.createObject("ADODB.Recordset")
Set rs2 = server.createObject("ADODB.Recordset")
conn.open="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &Server.MapPath("alumni.mdb") & ""
rs.open "select * from alumni",conn
%>
<div id="maincontent">
<div class="show">
<form name="form1" method="post"action="gallery.asp">
<h2 style="font:20px SegoeUI, 'Segoe UI', arial, sans-serif;margin: 0 auto;width: 300px;">Pictures of alumni in year:
<select name="drpyear" style="margin: 0 auto;width: 150px;height: 30px;text-align: center" onChange="javascript: document.forms['form1'].submit()" >
<%while NOT rs.EOF%>
<option onclick="javascript: document.forms['form1']">
<%response.write(rs("alumniyear"))%>
</option>
<%rs.MoveNext%>
<%wend%>
</select>
</h2>
</form>
<ul id="gallery">
<%alumniyear=Request("drpyear")
rs2.open "select * from gallery where alumni='"&alumniyear&"'",conn
if rs.EOF then%>
<li><img height="200"width="200" src=<%response.write(rs2("link"))%>></li>
<%else%>
<%while NOT rs2.EOF%>
<li><img height="200"width="200" src=<%response.write(rs2("link"))%>></li>
<%rs.MoveNext
WEND
end if
conn.Close
Set conn =Nothing%>
</ul>
</div>`
答案 0 :(得分:1)
您需要在while循环中检查构建选择选项的选项。 像这样的东西
<%while NOT rs.EOF%>
<option onclick="javascript: document.forms['form1']"
<% if (Request.Form("drpyear") = rs("alumniyear")) then response.write "selected='selected'"%>
>
<%response.write(rs("alumniyear"))%>
</option>
<%rs.MoveNext%>
编辑:更新代码以使用Request.Form(“drpyear”)而不是Request(“drpyear”)来最小化开销