ASP :: Dynamic Table
2001
Dynamic Table Layout - Classic ASP example of dynamic table layout depending on number of items returned from the database.
<%
Option Explicit
Dim Connection, Command, rsResults
Dim lPage, lPageCount, I, lMaxCount, lResultCount, lID
Dim theCount, remainder
Set Connection = CreateObject("ADODB.Connection")
Set Command = CreateObject("ADODB.Command")
Set rsResults = CreateObject("ADODB.Recordset")
' Retrieve the complete list
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open Application("DSNConn")
Set Command.ActiveConnection = Connection
Command.CommandType = 4
Command.CommandText = "S_Images"
Command.Parameters.Refresh
Command.Parameters(0) = lID
rsResults.Open Command
%>
<html>
<head>
<title>Portfolio</title>
<!--#INCLUDE file="header.asp"-->
</head>
<body>
Portfolio<br>
Click on a picture of a to view a larger image.
<table border="0" cellpadding="6" cellspacing="6">
<TR>
<%
theCount = 0
Do While Not rsResults.EOF
remainder = theCount Mod 3
If remainder = 0 then
If theCount <> 0 then
Response.Write "<TR>"
End If
End If
Response.Write "<TD valign=top><A HREF=""details.asp?ID=" & rsResults("ID") & """><img src=""../images/"
If Trim(rsResults("ThumbImage")) <> "" then
Response.Write rsResults("ThumbImage")
Else
Response.Write "none.gif"
End If
Response.Write """ width=100 height=100 border=0></A><br clear=all>"
If remainder = 2 then
Response.Write "</TR>" & VbCrLf
End If
theCount = theCount + 1
rsResults.MoveNext
Loop
' close out the last table row if its not already
If remainder = 0 then
Response.Write "<TD> </TD><TD> </TD></TR>" & VbCrLf
End If
If remainder = 1 then
Response.Write "<TD> </TD></TR>" & VbCrLf
End If
%>
</table>
<!--#INCLUDE FILE="footer.asp"-->