ASP Source Code:
<%Option Explicit%>
<!--#include file="ADOsetup.inc"-->
<HTML>
<HEAD>
<%SUB DrawPulldown
DIM strSQL,strMenu,ADOrsMenu
set ADOrsMenu = Server.CreateObject("ADODB.recordset")
strSQL = "Select DISTINCT Country from Customers ORDER BY Country"
ADOrsMenu.Open strSQL, ADOcn
Response.Write "<select name='txtSearch'>"
Response.Write "<option>Select Country</option>"
Do While Not ADOrsMenu.EOF
strMenu = "<option value='" & ADOrsMenu.Fields("Country") & "'>" & _
ADOrsMenu.Fields("Country") & "</option>" & vbCrLf
Response.Write(strMenu)
ADOrsMenu.MoveNext
Loop
Response.Write("</select>")
ADOrsMenu.Close
END SUB
%>
<%
DIM byName,byCity,byCo
DIM strSearch,strSort,strSQL,file
strSearch = Request.QueryString("txtSearch")
strSort = Request.QueryString("optSort")
IF (strSearch = "Select Country") THEN strSearch = ""
IF (strSort = "") THEN strSort = "ContactName"
strSQL = "Select * from Customers"
IF (strSearch <> "") THEN
strSQL = strSQL & " WHERE Country = '" & strSearch & "'"
strSQL = strSQL & " ORDER BY " & strSort
END IF
ADOrs.Open strSQL, ADOcn
file = "'Search5A.asp?txtSearch=" & strSearch & "&optSort="
byName = file & "ContactName'>Name"
byCity = file & "City'>City"
byCo = file & "CompanyName'>Company"
%>
</HEAD>
<BODY>
<H2>Search Results (Version 5A)</H2>
<HR>
<form action="Search5A.asp" method="get">
<input type="submit" value="Submit">
<%CALL DrawPulldown%><br><br>
</form>
<BR><A HREF='Search5A.asp'>Select all countries</A></th>
<HR>
<PRE>SQL string = [<%=strSQL%>]</PRE><BR>
<table border="1" width="80%">
<tr>
<th><A HREF= <%=byName%></A></th>
<th><A HREF= <%=byCo%></A></th>
<th><A HREF= <%=byCity%></A></th>
</tr>
<%do until ADOrs.EOF%>
<tr>
<td><%=(ADOrs.Fields("ContactName").Value)%>
<td><%=(ADOrs.Fields("CompanyName").Value)%>
<td><%=(ADOrs.Fields("City").Value)%>
<%ADOrs.MoveNext%>
</tr>
<%loop%>
</table>
<!--#include file="ADOclose.inc"-->
</BODY>
</HTML>