The HTML Table Formatter Component

In our previous example, and in examples you saw in the last chapter, we've come up against the need to display data from a table in our Web pages. This is a regular requirement and is, of course, the main reason that HTML sports the <TABLE> tag and the wide range of formatting options it offers.

However, we still have to manually create the <TR></TR> and <TD></TD> tags to get the layout right. There are tools that help to do this, but a sample component that is now available from Microsoft can do it all automatically. You can get the component from: http://www.microsoft.com/iis/usingiis/developing/samples

It's written in Java, so you'll also need to install the latest Java Virtual Machine (VM) from Microsoft, as well as the component. Because it's a sample, rather than part of ASP, you need to install it separately, but full instructions are included in the distribution file.

So what can it do? Well, it has four properties, and one method. The best way to learn about it is to see how we use it:

' Create a connection, and open it using the System DSN 'MyDatabase'
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "MyDatabase"

' Create a recordset containing the records from the table 'MyTable'
Set oRs = oConn.Execute("MyTable")

' Create an instance of the HTML Table Formatter Component
Set oTblfmt = Server.CreateObject("IISSample.HTMLTable")

' Now set its properties for the borders, caption, style and headings
oTblFmt.Borders = False
oTblFmt.Caption = "Displaying my data"
oTblFmt.CaptionStyle = "ALIGN=CENTER VALIGN=BOTTON"
oTblFmt.HeadingRow = True

' And insert the formatted table into the page
oTblFmt.AutoFormat(oRs)

If you are into creating components, you'll find the download worth it just to see how it's done—all the source code is included. And it certainly saves a lot of coding, and keeps the actual size of the page down as well!