I am trying to populate a dropdown with name titles (Mr, Mrs etc) and set the selected value to whatever value is in the database for that record. However, there are plenty of records in the database without a title. Currently in this situation the dropdown does not get populated and remains empty. Can anybody tell me what is wrong with my code (see below)?
<td>
<%
set objCmd = server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = strConnection2
objCmd.CommandType = adCmdStoredProc
objCmd.CommandText = "GetContactTitles"
set rsContactTitles = objCmd.Execute
%>
<select name=ContactTitle><%
do while not rsContactTitles.eof
'if a code has been selected, set it as selected
if (Not IsNull(rsLog("Title"))) then
if (rsContactTitles("ContactTitle") = rsLog("Title"))then
Response.Write "<option value=" & rsContactTitles("ContactTitle") & " selected>"& rsContactTitles("ContactTitle")& "</option>"
else
Response.Write "<option value=" & rsContactTitles("ContactTitle") & " >"& rsContactTitles("ContactTitle") & "</option>"
end if
'if no code has been selected, set it as selected
end if
rsContactTitles.movenext
loop
set rsContactTitles = nothing
set objCmd = nothing
%>
</select>
</td>
<td>
<%
set objCmd = server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = strConnection2
objCmd.CommandType = adCmdStoredProc
objCmd.CommandText = "GetContactTitles"
set rsContactTitles = objCmd.Execute
%>
<select name=ContactTitle><%
do while not rsContactTitles.eof
'if a code has been selected, set it as selected
if (Not IsNull(rsLog("Title"))) then
if (rsContactTitles("ContactTitle") = rsLog("Title"))then
Response.Write "<option value=" & rsContactTitles("ContactTitle") & " selected>"& rsContactTitles("ContactTitle")& "</option>"
else
Response.Write "<option value=" & rsContactTitles("ContactTitle") & " >"& rsContactTitles("ContactTitle") & "</option>"
end if
'if no code has been selected, set it as selected
end if
rsContactTitles.movenext
loop
set rsContactTitles = nothing
set objCmd = nothing
%>
</select>
</td>