Displaying Listboxes and Hyperlinks with GetString
By Robert Monteiro
Recently I was searching 4Guys for information on GetString, an ADO method that
converts a Recordset's contents into a compact string with user-defined delimiters. The purpose of using
GetString is to greatly speed up the construction of blocks of data-embedded HTML, such a
HTML TABLES. In my search for information on GetString, I came across a previous
article entitled: Speeding Up ASP by Using GetString.
Throughout the article I noticed a mention about populating listboxes
using GetString... however, I could not find any bit of code relating to this, so I decided to
write my own! In this article I'd like to show you how to populate a listbox using GetString,
and also how to create a list of hyperlinks from a database. If you are not familiar with GetString,
I highly recommend that you read Speeding Up ASP by Using GetString
first, since I will not delve into details on how GetString works.
Populating Listboxes with GetString
Before we examine the code, let's look at the functional syntax for GetString
(all parameters are optional):
String = recordset.GetString(StringFormat, NumRows, ColumnDelimiter, RowDelimiter, NullExpr)
|
Note that for our examples we'll be using the ColumnDelimiter, RowDelimiter, and
NullExpr parameters, which specify, respectively, what string to delimit each Recrodset column with, what string
to delimit each Recordset row with, and what string to use if a Recordset cell contains a NULL value.
Also, you can try out each of these scripts I've included in my article! Just click on the View Live Demo
link at the conclusion of the code!
|
While the above script may seem nice, many developers would like enhance the code so that instead of producing HTML output like:
|
it would populate each row's unique ID in the VALUE parameter of the OPTION tag like so:
|
To accomplish this we only need to make a few minor changes. First, in our SQL statement, we'll need to grab the unique ID in the SELECT statement:
Dim mySQL
|
and then we'll need to alter the GetString statement some:
|
That's it!
In Part 2 we'll examine how to construct a list of database-created
hyperlinks using GetString. I'll be presenting a bit of I think most developers will want
to use quite often!




