<html>
<title>Test</title>
<body bgcolor="FFFFFF">
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=123;Data Source=1234"
Set rs = Server.CreateObject("ADODB.Recordset")
SQL = "select * from 1234"
rs.open SQL, conn
response.write("<table border='1'>")
While Not rs.EOF
response.write("<tr><td>" & rs("Name") & "</td><td>" & rs("PID") & "</td><td>" & rs("Coords") & "</td><td>" & rs("Items") & "<select size='3' name='itemlist'>Array through option tags here????</select></td></tr>")
rs.MoveNext
Wend
response.write("</table>")
rs.close
conn.close
Set rs = Nothing
Set conn = Nothing
%>
</body>
</html>
我的rs(“Items”)包含许多以逗号分隔的值,我想将每个项目添加到列表框中。有人能指出我正确的方向吗?谢谢!
答案 0 :(得分:1)
您可以将while / wend循环中的response.write行更改为this,这将创建一个带有逗号分隔值的选择框(“Items”):
response.write("<tr><td>" & rs("Name") & "</td><td>" & rs("PID") & "</td><td>" & rs("Coords") & "</td><td><select size='3' name='itemlist'>")
Dim opts, i
opts = Split(rs("Items"), ",")
For i = 0 To UBound(opts)
response.write("<option>" & opts(i) & "</option>")
Next
response.write("</select></td></tr>")
如果你需要做更复杂的事情,比如有单独的选择值/文本,或者需要预先选择一个选项,那么你需要对此进行扩展。