编辑表单,表单中有下拉框,如何在下拉框中显示已经选择的存在数据库中的值。比如下拉框中有三个选项:
北京,上海,南京;原来选择的是南京,现在修改表单,怎么在编辑的页面的下拉框中显示上次的选择:南京?
<select name="select" class="select" id="select">
<option <%if instr(rs("city"),"北京")=0 then%> value="北京" <%else%> selected value="北京" <%end if%>>北京</option>
<option <%if instr(rs("city"),"上海")=0 then%> value="上海" <%else%> selected value="上海" <%end if%>>上海</option>
</select>
<select name="sel">
<%
Set rs=Conn.Execute("Select * From Pro ")
Do While Not(rs.Eof)
%>
<option value="<%= rs("Pro_Name") %>" <% If rs("rs_Name")=xxxxx Then Response.Write"selected" end if%>>
<%= rs("rs_Name") %>
</option>
<%
rs.Movenext
Loop
rs.Close
Set rs=Nothing
%>
</select>
循环判断
循环显示数据库数据的下拉列表
<tr><td width="17%" bgcolor="#FFFFFF" >礼 物:</td><td width="83%" bgcolor="#FFFFFF" ><select name="liwuID">
<option value="0">无 礼 品</option>
<% 显示数据库内容
选择开始
strSQL = "SELECT * FROM liwu"
执行SQL的数据库查询
Set objRS = Server.CreateObject("ADODB.Recordset")
objrs.open strsql,conn,1,1
检查是否有记录
If Not objRS.Eof Then
Do While Not objRS.Eof %>
<option value="<%=objRS("liwuid")%>"><%=objRS("liwuname")%></option>
<% objRS.MoveNext 移到下一条记录
Loop %> <A href="addliwu.asp">添加礼品赠品</a>
</td>
</tr>
<select name="select" class="select" id="select">
<option <%if rs("city")="北京" then response.write "selected">北京</option>
<option <%if rs("city")="上海" then response.write "selected">上海</option>
</select>