0
我有一個簡單的代碼填充數據庫表中的選擇對象。我想檢查一個值來將條目設置爲選中狀態,但是當我檢查一個數據庫值時,我會得到一個空的選擇框。此代碼將產生空箱:經典ASP:使用If語句時的空選擇
response.write "<td><select name='FromDept'>"
Do While not rs.eof
If rs("DeptID") = 61 Then
response.write "<option value=" & rs("DeptID") & " selected>" & rs("DeptName") & "</option>"
Else
response.write "<option value=" & rs("DeptID") & ">" & rs("DeptName") & "</option>"
End If
rs.MoveNext
Loop
rs.close
response.write "</select></td>"
但是,此代碼生成一個選擇框的值:
response.write "<td><select name='FromDept'>"
LpCnt = 0
Do While not rs.eof
If LpCnt = 9 Then
response.write "<option value=" & rs("DeptID") & " selected>" & rs("DeptName") & "</option>"
Else
response.write "<option value=" & rs("DeptID") & ">" & rs("DeptName") & "</option>"
End If
rs.MoveNext
LpCnt = LpCnt + 1
Loop
rs.close
response.write "</select></td>"
感謝您的幫助!
看這裏 - http://stackoverflow.com/a/2032140/763026 –