2012-10-04 69 views
-1

我想在這裏執行的操作是根據組合框中選擇的選項加載圖片。但是,當我從頁面後,組合框中選擇「2011」重新載入選擇的選項2012 again..plz幫我.... THIS IS MY ASP代碼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>` 

回答

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」),而不是請求「(drpyear」),以儘量減少開銷

+0

謝謝你這麼多,果然奏效。 ..但你能解釋我的代碼.. **

+0

@ user1720452代碼中的添加檢查發佈的請求值是否等於您的記錄「alumniyear」值。如果是,則設置「selected」在致敬的選項元素(http://www.w3schools.com/tags/att_option_selected.asp) – AardVark71

+0

您好工作時,我從組合框中選擇一個選項。但是當頁面首次加載時。代碼<%request(「drpyear」)。count%>返回0,但項目被加載到組合框中。 – Vishal