Scrolling Div Tags to Create HTML Grid

Recently, I was asked to write a function in ASP that would dynamically create a multi-column HTML table based on the results from a database.

Recently, I was asked to write a function in ASP that would dynamically create a multi-column HTML table based on the results from a database. Five minutes later, I was asked to put it in a scrolling grid-like table.

Well, here is the results of that work. This example should work relatively well in Netscape but you'll probably have to put in some page reload code as NS doesn't handle that particular well.

Here's another link of interest on this subject:

DHTML Sortable Grid Control (100% Client Side With Form Element Sort)

http://www.eggheadcafe.com/articles/20021022.asp


<HTML>

<STYLE type="text/css">

DIV.clsDataGrid
{
BORDER-RIGHT: none;
BORDER-TOP: none;
BORDER-LEFT: none;
BORDER-BOTTOM: none;
OVERFLOW: scroll;
WIDTH: 400px;
HEIGHT: 250px
}

</STYLE>
<BODY>
<table border=0 align=center cellspacing=0 cellpadding=0 width='80%' >
<tr><td align=left>
<div class=clsDataGrid id=divList bgcolor=white>

<%

Sub ArrayToTable(sArray,nCols)

dim nTot
dim nCur
dim nRecCnt
dim sH

nTot = Ubound(sArray,2)
nRecCnt = 0

For nCur = 1 To nTot

if nRecCnt = 0 then sH = sH & "<tr>"

nRecCnt = nRecCnt + 1

sH = sH & "<td align=left>" & sArray(1,nCur) & " . " & sArray(2,nCur) & "</td>"

if nRecCnt = nCols then
sH = sH & "</tr>"
nRecCnt = 0
end if

Next

if nRecCnt > 0 then sH = sH & "<td colspan=" & nCols - nRecCnt & ">?</td>"
if Right(Trim(sH), 4) <> "</tr>" Then sH = sH & "</tr>"

sH = sH & "</table>"
Response.Write "<table width='100%' border=2 cellspacing=1 cellpadding=1>" & sH & "</table>"

End Sub

Function CreateTestArray(nTot)

dim sArray()
dim nCur

Redim sArray(2,nTot)

For nCur = 1 To nTot
sArray(1,nCur) = nCur
sArray(2,nCur) = "Description"
Next

CreateTestArray = sArray

end function


Call ArrayToTable(CreateTestArray(52),5)

%>

</div>
</td></tr>
</table>
</BODY>
</HTML>


Submission Date:  9/23/2005 2:46:46 PM
Submitted By:  Robbe Morris
My Home Page:  http://www.robbemorris.com

By Robbe Morris   Popularity  (722 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP