为什么这个经典的 ASP 下拉菜单没有选择正确的值?
Why is this classic ASP dropdown not selecting the correct values?
循环中的前几个下拉菜单将正常工作(这是从 SQL 获取的 3 条测试记录)。为什么这个 select 将列表中的最后一个值作为第三个值,然后继续 select 所有空 clientnos() 值的最后一个值?
<%For k = 0 to 4%>
<td colspan ="5"><select name = "clientnos(<%=k%>)" id="aliasInput" >
<option value=""></option>
<%
strSQL1 = "select cno, aliasname from Clients order by Aliasname asc"
Set rs1 = objConnection.Execute(strSQL1, ,adCmdText)
call ErrorHandler(err)
arr1 = rs1.GetRows()
for i = 0 to UBound(arr1,2)
cno = trim(arr1(0,i))
aliasname = trim(arr1(1,i))
%>
<%if cno <> clientnos(k) Then%><option value = "<%=cno%>"><%=aliasname%></option><%end if%>
<%if cno = clientnos(k) Then%><option value = "<%=cno%>" selected><%=aliasname%></option><%end if%>
<%
next
%>
</select></td>
<%next%>
我通过最初默认为空白选择修复了不正确的选择,并发现下拉列表的初始值导致下拉列表中最后一条记录不正确的问题。这是更正后的代码。
<td colspan ="5"><select name = "selectedclientnos(k)" id="aliasInput" >
<option value="" selected></option>
<%
strSQL1 = "select cno, aliasname from Clients order by Aliasname asc"
Set rs1 = objConnection.Execute(strSQL1, ,adCmdText)
call ErrorHandler(err)
arr1 = rs1.GetRows()
for i = 0 to UBound(arr1,2)
cno = trim(arr1(0,i))
aliasname = trim(arr1(1,i))
%>
<%if cno <> clientnos(k) Then%><option value = "<%=cno%>"><%=aliasname%></option><%end if%>
<%if cno = clientnos(k) Then%><option value = "<%=cno%>" selected><%=aliasname%></option><%end if%>
<%
next
%>
循环中的前几个下拉菜单将正常工作(这是从 SQL 获取的 3 条测试记录)。为什么这个 select 将列表中的最后一个值作为第三个值,然后继续 select 所有空 clientnos() 值的最后一个值?
<%For k = 0 to 4%>
<td colspan ="5"><select name = "clientnos(<%=k%>)" id="aliasInput" >
<option value=""></option>
<%
strSQL1 = "select cno, aliasname from Clients order by Aliasname asc"
Set rs1 = objConnection.Execute(strSQL1, ,adCmdText)
call ErrorHandler(err)
arr1 = rs1.GetRows()
for i = 0 to UBound(arr1,2)
cno = trim(arr1(0,i))
aliasname = trim(arr1(1,i))
%>
<%if cno <> clientnos(k) Then%><option value = "<%=cno%>"><%=aliasname%></option><%end if%>
<%if cno = clientnos(k) Then%><option value = "<%=cno%>" selected><%=aliasname%></option><%end if%>
<%
next
%>
</select></td>
<%next%>
我通过最初默认为空白选择修复了不正确的选择,并发现下拉列表的初始值导致下拉列表中最后一条记录不正确的问题。这是更正后的代码。
<td colspan ="5"><select name = "selectedclientnos(k)" id="aliasInput" >
<option value="" selected></option>
<%
strSQL1 = "select cno, aliasname from Clients order by Aliasname asc"
Set rs1 = objConnection.Execute(strSQL1, ,adCmdText)
call ErrorHandler(err)
arr1 = rs1.GetRows()
for i = 0 to UBound(arr1,2)
cno = trim(arr1(0,i))
aliasname = trim(arr1(1,i))
%>
<%if cno <> clientnos(k) Then%><option value = "<%=cno%>"><%=aliasname%></option><%end if%>
<%if cno = clientnos(k) Then%><option value = "<%=cno%>" selected><%=aliasname%></option><%end if%>
<%
next
%>