Database driven select list

Example Code

First include the class at the top of the page:

<!--#include file="SelectList.class.asp" -->

Then programmatically script the HTML for a select list in as little as 5 lines of code.
Creating code with the select list class is as simple as:

<%
' Create instance of SelectList Class
Dim mySelect : Set mySelect = New SelectList
' Set the select tag's ID and Name
mySelect.SelectID = "SelectMe"
' Set as many manual options as you want
- [OPTIONAL]
mySelect.AddOption = "<option value=''>Please Select </option>"
' The SQL can only contain two values: [ID] First - [Label] Second
mySelect.SQL ="SELECT x AS value, y AS name FROM z "
mySelect.ConnString = myConn ' The Connection string to the DB
' The pre select values can be an integer an array or a comma separated list of values to pre select - [OPTIONAL]
mySelect.PreSelect = 25
Dim SelectList : SelectList = mySelect.SelectList() ' Returns the HTML
%>

You can then Response.Write(SelectList) any where in your page
I like to wrap the above in a function that returns the HTML, e.g.

<%
Function listAuthors()

Dim strSQL : strSQL = "SELECT au_id AS ID, (au_fname + ' ' + au_lname) as Author FROM authors"
Dim AuthorSelect : Set AuthorSelect = New SelectList ' Create instance of SelectLise Class
AuthorSelect.SelectID = "Author_ID" ' Set the select tag's ID and nmae
AuthorSelect.AddOption = "<option value=''>Select an Author</option>" ' Set as many manual options as you want
AuthorSelect.AddOption = "<option value='' disabled>Do not select me</option>" ' disabled options only work in Firefox
AuthorSelect.SQL = strSQL ' The SQL can only contain two values: [ID] First - [Label] Second
AuthorSelect.ConnString = con_Access ' The Connection string to the DB
AuthorSelect.SelectTagExt = "size='8' multiple='multiple'" ' embed extentions to the select tag - could use onclick for javascript auto submissions
' The pre select values can be an integer an array or a comma separated list of values to pre select
AuthorSelect.PreSelect = array("213-46-8915","267-41-2394","341-22-1782")
AuthorSelect.Debug = True ' Get extra error info
listAuthors = AuthorSelect.SelectList() ' Returns the HTML
' alternatively you can generate a hierarchy from a datashape SQL by using - AuthorSelect.SelectListfromDataShape(3)
' Dont forget to pass the level as in integer and add - "Provider=MSDataShape; Data " & ConStr - to the connection string

End Function
%>

Here's the result:

More than 1 manual options