This browser does not support basic Web standards, preventing the display of our site's intended design. May we suggest that you upgrade your browser?

Web Development Code Library ASPGenerate dropdown from database table

Generate dropdown from database table

A function that will create a dropdown list box from a set of data you specify

' Assumes you have the <SELECT></SELECT> tags prepared outside of this function
' Assumes you have an ADO Connection called objCon that is available to this function.

' Input: Table as string, Description field as string, value field as string
' Output: A string of HTML containing your dropdown list


Function MakeSelectBox( table, DescField,  ValueField)

     strSQL = "SELECT " & ValueField & " , " & DescField & " FROM " & table
     set objRSTemp = objCon.Execute(strSQL)

     %><OPTION SELECTED VALUE="<%= objRSTemp.fields(ValueField) %>"><%= objRSTemp.Fields(DescField) %><% 
     objRSTemp.movenext

        Do While NOT objRSTemp.eof
           %><OPTION VALUE="<%= objRS.fields(ValueField) %>"><%= objRS.Fields(DescField) %><% 
          objRS.movenext
     Loop
     set objRS = nothing

End Function
Excellence. Our Measure. Our Motto. Our Goal.