Hyperlinked dropdown menu selection box with select options filled dynamically from Access database on ASP page.

Using the simple database display code from http://www.asp101.com/samples/viewasp.asp?file=db%5Fsimple%2Easp and the dropdown menu explanation from http://www.felgall.com/htmlt20.htm you can have a dynamic dropdown linked selection box menu.

What is really nice about this is that you can have multiple dropdown menu boxes if you like on the same page. The following examples show three different menus served from a single table [horsedata] with each menu filtering the data differently.

Stallions
Broodmares
For Sale

The table below shows the code for the three menu boxes displayed above. Note that one single database connection and set of declarations and recordset closure is used for all three menus.

If I've saved you some
time or given you some
ideas, please rate
.
Rated:
by Aspin.com users
What do you think?
<%
Dim cnnSimple ' ADO connection
Dim rstSimple ' ADO recordset
Dim strDBPath ' path to our Access database (*.mdb) file

strDBPath = Server.MapPath("AccessDatabase.mdb")
Set cnnSimple = Server.CreateObject("ADODB.Connection")
cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"

%>

<table border="1" width="100%" bgcolor="#000080">
<tr>
<td align="center"><table border="1">
<tr>
<td>
<%
Set rstSimple = cnnSimple.Execute("SELECT * FROM [horsedata] WHERE [gender]='"&"Sire"&"'")
%>
<form name="ex2" action="dropdown_selection_box_hyperlinked_menu_from_database.asp" method="POST">
<select name="GALLERYCAT" size="1">
<% Do While Not rstSimple.EOF %>
<option value="<%= rstSimple.Fields("ID").Value %>">#<%= rstSimple.Fields("ID").Value %> - <%= rstSimple.Fields("Horse Name").Value %></option>
<%
rstSimple.MoveNext
Loop
%>
</select>
<input type="submit" value="Go!">
</div>
</form>
</td>
</tr>
</table>
<font color="#FF0000"><b>Stallion</b></font><b><font color="#FF0000">s
</td>
<td align="center">

<%

Set rstSimple = cnnSimple.Execute("SELECT * FROM [horsedata] WHERE [gender]='"&"Broodmare"&"'")
%>

<table border="1">
<tr>
<td>
<form name="ex2" action="dropdown_selection_box_hyperlinked_menu_from_database.asp" method="POST">
<select name="GALLERYCAT" size="1">
<% Do While Not rstSimple.EOF %>
<option value="<%= rstSimple.Fields("ID").Value %>">#<%= rstSimple.Fields("ID").Value %> - <%= rstSimple.Fields("Horse Name").Value %></option>
<%
rstSimple.MoveNext
Loop
%>
</select>
<input type="submit" value="Go!">
</div>
</form>
</td>
</tr>
</table>
<font color="#FF0000"><b>Broodmares</b></font></td>
<td align="center">

<%
Set rstSimple = cnnSimple.Execute("SELECT * FROM [horsedata] WHERE [for-sale]='"&"Yes"&"'")
%>
<body style="font-family: Verdana">

<table border="1">
<tr>
<td>
<form name="ex2" action="dropdown_selection_box_hyperlinked_menu_from_database.asp" method="POST">
<select name="GALLERYCAT" size="1">
<% Do While Not rstSimple.EOF %>
<option value="<%= rstSimple.Fields("ID").Value %>">#<%= rstSimple.Fields("ID").Value %> - <%= rstSimple.Fields("Horse Name").Value %></option>
<%
rstSimple.MoveNext
Loop
%>
</select>
<input type="submit" value="Go!">
</div>
</form>
</td>
</tr>
</table>
<b><font color="#FF0000">For Sale</td>
</tr>
<tr>
<td align="center" colspan="3" bgcolor="#FF0000"><b>
<font color="#FFFFFF"><%if NOT request.form("GALLERYCAT")="" then %>Display record number: <%= request.form("GALLERYCAT") %><% end if %></font></b></td>
</tr>
</table>

<%
rstSimple.Close
Set rstSimple = Nothing
cnnSimple.Close
Set cnnSimple = Nothing
%>


Classic ASP Active Server Pages Examples, code, tutorials, scriptsASP Examples Menu (below*)



Active Server Pages | ASP | Scripts | Tutorials | Code | Web Programming | Examples
Active Server Pages ASP code examples, tutorials, and snippets for use in Programming interactive websites.

NOTE: Recently changed hosting and url so some demos aren't working now because I haven't updated pathing; if you find omissions or errors let me know.
 

*

Multiple records per row with paging

Display multiple records per row

Get ID of newly inserted record, Classic ASP, Access Database

Javascript timer with ASP to keep track of time expired until login expires / timeout session is up

Multiple Javascript event functions triggered from single form onsubmit

Get Querystring key names along with querystring variables

ASP Youtube Downloader  Version FOUR
All ASP code. Allows user client side downloads of Youtube videos. You have the option to allow files to be saved directly to your site also.

ASP/PHP video downloader (Works better than ASP for large files)

Use ASP to dynamically parse a Youtube XML playlist to render to html.

Zip up an archive file of your site for backup if you need to restore website with ASP and free Zip Component.

Zip all files in a folder into an archive or backup file dynamically by specific file extension.

Sanitize or clean price cost field for database insertion or display.

Javascript image dimensions and image file size preview.

Put recordset into array, assign keys to the records then use record associated with specific array key as a variable elsewhere.

Access Database Interface Generator Wizard to read your table and field names and to create a table display.

Combining dropdown selection box menu with dynamic ASP database page.

How to redirect user to original page they tried to view before logging, after they are logged in.

Previous/Current/Next Records, or Buddy Ring Script

Custom ASP 404 page not found error script sends visitors to virtual folders

ASP Example: Combine ASP with Javascript for popup windows
dynamically sized to image dimensions.

ASP Example: How to use ASPJPEG to create thumbnails
Click for free Highly recommended thumbnailer for which you don't need Server access

ASPjpeg: How to re-scale aspect ratio of thumbnails by height instead of width.

ASP Example: What if your host has an older version of ASPJPEG that doesn't support gifs?

Using inline frames as "dynamic includes" (offline for updating)

Select Count Distinct Records for Access Database

Upload Image to folder and insert filename into database

Get date in such a way that it can be made part of a file name

Isolate a file name away from its path or extension or strip a path from a file name or strip characters from database field

User-customized on-the-fly stylesheet css files

Enhanced Page Hits Counter (also counts downloads and menu link hits)

Loop through array and compare to string with select case

Aphabetical Paging for your ASP scripts

Web Wiz Guide's Site Searcher Script modified as a file content indexer

Let Users Select How Many Records to View

Access Database for your PayPal IPN scripts

Miscellaneous collected code

You don't have to be a genius, just persistent, to write original Active Server Pages scripts

Software Recommendation: bare_bones_no_bells_and_whistles_asp_code_generator_database_interface_maker

--Lil at gmail.com