Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing QueryString With DB Record 1

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
I have a page named Page1.asp?CID=45. This page has a drop-down menu which lists the records (FirstName & LastName) from a database table. Now what I want is when the user whose CID=45 comes to this page, in the drop-down menu, CID=45 will be selected by default. If say a user whose CID=75 comes to this page, then the drop-down menu should show CID=75 as selected by default i.e. depending on the CID value retrieved from the querystring, the drop-down menu will change the default selected option. This is what I am doing to accomplish this:
Code:
<%
   Dim objConn,objRS,strSQL
   Set objConn=CreateObject(&quot;ADODB.CONNECTION&quot;)
   ..............
   Set objRS=CreateObject(&quot;ADODB.RECORDSET&quot;)

   strSQL=&quot;SELECT * FROM DBTable&quot;
   objRS.Open strSQL,objConn
%>
<select name=&quot;contacts&quot;>
<%
   Do Until(objRS.EOF)     
      If(objRS(&quot;ContactID&quot;)=Request(&quot;CID&quot;)) Then
%>
<option value=&quot;<%= objRS(&quot;ContactID&quot;) %>&quot;
Code:
selected
Code:
><%= objRS(&quot;FirstName&quot;) & &quot; &quot; & objRS(&quot;LastName&quot;) %></option>
<%
      Else
%>
<option value=&quot;<%= objRS(&quot;ContactID&quot;) %>&quot;><%= objRS(&quot;FirstName&quot;) & &quot; &quot; & objRS(&quot;LastName&quot;) %></option>
<%
      End If
      objRS.MoveNext
   Loop
%>
</select>

But the above code doesn't select by default that option in the drop-down menu which is the value of the querystring CID. What is wrong with the above code?

Thanks,

Arpan
 
Perhaps the database field and the querystring are of different types. I assume that the ContactID field has a type 'Int'. Try casting the querystring to an int.

Code:
CInt(Request(&quot;CID&quot;))

Mitch




What happens if you get scared half to death twice?
 
Hi Mitch,

Thanks for your idea. It worked perfectly. I should have thought about this solution before posting my question. Anyway thanks once again.

Regards,

Arpan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top