经典ASP - 在下拉列表中检索会话变量

时间:2022-11-27 01:40:56

I have a little issue I'm stuck with and can't figure out the best way of resolving this issue. I have a drop down list, which is populated from an SQL result set. When the user proceeds to the next page, it keeps the "shortcode" in a session to be used over the next few steps, but when the user goes back to the new test page, I need the drop down menu to hold the username of the person testing (via the session created earlier on). How would I achieve this?

我有一个小问题,我一直坚持,无法找出解决这个问题的最佳方法。我有一个下拉列表,它是从SQL结果集中填充的。当用户进入下一页时,它会在会话中保留“短代码”,以便在接下来的几个步骤中使用,但是当用户返回到新的测试页面时,我需要下拉菜单来保存用户名测试的人(通过之前创建的会话)。我怎么做到这一点?

Here is my asp code:

这是我的asp代码:

Operator<br />
    <select name="operator" class="rounded" >
    <optgroup label="Please select the operator">
    <%
    sql = "SELECT * FROM [ProductTestData].[dbo].[CLS_Test_Users]"
    rs.Open sql,conn
    While not rs.eof
        response.write("<option value=" & rs("shortcode") & ">" & rs("username") & "</option>")
        rs.movenext
    Wend
    rs.close
    %>
    </optgroup>
    </select>

The "shortcode" is just the user's initials which are eventually converted back to their full name to insert into SQL. The "shortcode" is stored in session("operator")

“短代码”只是用户的首字母,最终转换回其全名以插入SQL。 “短代码”存储在会话中(“操作员”)

1 个解决方案

#1


1  

You need to add the selected attribute on the option that needs to be selected. Here is how:

您需要在需要选择的选项上添加所选属性。方法如下:

While not rs.eof
    response.write("<option value=" & rs("shortcode"))
    if rs("shortcode") & "" = session("operator") then
        response.write(" selected")
    end if
    response.write(">" & rs("username") & "</option>")
    rs.movenext
Wend

#1


1  

You need to add the selected attribute on the option that needs to be selected. Here is how:

您需要在需要选择的选项上添加所选属性。方法如下:

While not rs.eof
    response.write("<option value=" & rs("shortcode"))
    if rs("shortcode") & "" = session("operator") then
        response.write(" selected")
    end if
    response.write(">" & rs("username") & "</option>")
    rs.movenext
Wend