Data Access and Transactions |
When using a server-side script to fill a list box for use on the client’s HTML page, keep in mind that the list box doesn’t exist yet when your server-side code is executed. For this reason, you need to generate client-side code using server-side scripting. You can use either the standard HTML SELECT tag (which creates a drop-down list box), or a custom ActiveX Listbox control. Using the SELECT tag, you simply use server-side HTML to fill in the VALUEs. The following example demonstrates how you could fill in a SELECT control from an ADO Recordset:
<SELECT>
<% Do While NOT rs.EOF %>
<OPTION VALUE="<%= rs("Name") %>"><%= rs("Name") %></OPTION>
<% rs.MoveNext
Loop %>
</SELECT>
When you are working with client-side ActiveX objects like the Listbox control, it’s a good idea to use server-side scripting to programmatically pass values to ListBox.AddItem calls during the Window_OnLoad event. Here is an example (the groups of double quotation marks are used to keep the Name data together as a string):
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Window_OnLoad()
<% Do While NOT rs.EOF
Response.Write "ListBox.AddItem """" & rs("Name") & """" & vbCr
rs.MoveNext
Loop %>
End Sub
· >
</SCRIPT>