VBS - 下拉列表每隔一行生成默认选项

时间:2016-06-23 18:56:25

标签: vbscript

我的VBS下拉列表每隔一个列表显示“全部”选项。

我知道问题出在我的选项值中,但我不知道如何解决这个问题,我们将不胜感激。

<% 
Dim DataConn
Dim customersel
Dim SQL

Set DataConn = Server.CreateObject("ADODB.Connection")
Set customersel = Server.CreateObject("ADODB.Recordset")
%>

<%
DataConn.Open "DSN=***;UID=***;PWD=***"

SQL = "select customername FROM log.dbo.customer order by customerName"
customersel.Open SQL, DataConn
%>

<select Name="customersel" id="customersel">
<%While Not customersel.EOF%>
<% if Request.Form("customersel") = "0" then %>
<option value="0" selected>All
<% else %>
<option value="0">All
<% end if %>
<option value="<%= customersel("customername") %>"><%= customersel("customername") %></option>

<%
customersel.MoveNext
Wend

customersel.Close
Set customersel = Nothing
DataConn.Close
Set DataConn = Nothing
%>
</select>

Trudeau Fernandes解决方案:

    <select Name="customersel" id="customersel">
    <% if Request.Form("customersel") = "0" then %>
    <option value="0" selected>All</option>
    <% else %>
    <option value="0">All</option>
    <% end if %>
    <%While Not customersel.EOF%>
    <option value="<%= customersel("customername") %>"><%= customersel("customername") %></option>

1 个答案:

答案 0 :(得分:1)

将if块移到循环外面。并确保关闭&#39; All&#39;的选项标签。选项..