|
||
| Inside Technique : Building Lists from your Database A common operation when working with databases on the web is to populate a list box with the results of a query.
On SiteExperts, we use a function, Our BuildListBox function generates single or multiselect list boxes as well as alternative representations using radio buttons or checkboxes. The BuildListBox is a relatively simple function that takes 8 arguments:
function BuildListBox(sFormat,sName,bMulti,iSize,sExtra,oRS,sValueField,sTextField)
Dim str
' Setup SELECT list
if sFormat="SELECT" then
str = "<SELECT"
if (sName<>"") then str = str & " NAME=""" & sName & """"
if (bMulti) then str = str & " MULTIPLE "
if (iSize>0) then str = str & " SIZE=""" & iSize & """"
if (sExtra<>"") then str = str & " " & sExtra
str = str & ">"
end if
while not oRS.eof
str = str & chr(13) & chr(10)
select case sFormat
case "SELECT": ' Create option
str = str & "<OPTION"
case "INPUT": ' Create radio or checkbox
str = str & "<INPUT NAME=""" & sName & """ TYPE="
if bMulti then
str = str & """checkbox"""
else
str = str & """radio"""
end if
end select
if sValueField<>"" then str = str & " VALUE=""" & oRS.fields(sValueField) & """"
str = str & ">" & oRS.fields(sTextField)
if sFormat="INPUT" then str = str & "<BR>"
oRS.movenext
wend
' Close SELECT list
if sFormat="SELECT" then str = str & "</SELECT>"
BuildListBox = str
End Function
Next we explain how to use the BuildListBox function. Page 1:Building Lists from your Database © 1997-2000 InsideDHTML.com, LLC. All rights reserved. |