ASP drop down box to list information from 2 SQL Server columns

时光总嘲笑我的痴心妄想 提交于 2019-12-25 13:35:12

问题


I've got a drop down list of customers. However, some of those customers get listed 2 or 3 times because they have multiple cities. What I would like to do is include the city in the same drop down list next to the city so that each entry is unique

<%
Dim DataConn
Dim custsel
Dim SQL

Set DataConn = Server.CreateObject("ADODB.Connection")
Set custsel = Server.CreateObject("ADODB.Recordset")
DataConn.Open "DSN=***;UID=***;PWD=***;"

SQL = "select custname, city FROM log.dbo.Customers order by CustName"
custsel.Open SQL, DataConn
%>

<table align="center" border="0">
    <tr><th colspan="2"><b>Test Billing Transaction Summary</b></th></tr>
    <tr><td colspan="2"><hr color="#ff7f26"></td></tr>
    <tr><td width="50%" align="right">Customer Selection: </td>
        <td width="50%" align="left">
            <select name="custsel" id="custsel">
                    <% if Request.Form("custsel") = "All" then %>
                <option value="All" selected>All</option>
                    <% else %>
                <option value="All">All</option>
                    <% end if %>
                    <%While Not custsel.EOF%>
                <option value="<%= custsel("custname") %>"><%= custsel("custname") %></option>
<%
custsel.MoveNext
Wend

custsel.Close
Set custsel = Nothing
DataConn.Close
Set DataConn = Nothing
%>
            </select>
        </td>
    </tr>
    <tr><td align="right">Summary Type: </td>
        <td align="left"><select name="datetype" id="datetype">
                <option value="">Date Type:</option>
                <option value="LTD">Last Trade Day</option>
                <option value="MtD">Month to Date</option>
                <option value="YtD">Year to Date</option>
            </select>
        </td>
    </tr>
    <tr><td align="right">Start Date: <input value="" type="text" name="datepickstart" id="datepickstart" required></input></td>
        <td align="left">End Date: <input value="" type="text" name="datepickend" id="datepickend" required></input></td>
    </tr>
    <tr><td colspan="2"><input type="submit" value="Execute" id="billingsubmit"></td></tr>
    <tr><td colspan="2"><hr color="#ff7f26">
        </td>
    </tr>
</table>

回答1:


I changed the final line in my select box to:

<option value="<% =custsel("custname") %>" + "<% =custsel("city") %>"><% =custsel("custname") %> :<% =custsel("city") %></option>

However, I'd like to be able to call on the "CustName" and the "City" independently on the next page.

I'm currently calling the custname with:

<% dim custselect custselect = request.form("custsel") %>

Can I call on the city with:

<% dim cityselect cityselect = request.form("custsel") %>


来源:https://stackoverflow.com/questions/38379361/asp-drop-down-box-to-list-information-from-2-sql-server-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!