% '******************************************************* '* ASP 101 Sample Code - http://www.asp101.com/ * '* * '* This code is made available as a service to our * '* visitors and is provided strictly for the * '* purpose of illustration. * '* * '* http://www.asp101.com/samples/license.asp * '* * '* Please direct all inquiries to webmaster@asp101.com * '******************************************************* %> <% ' Data source specific vars Dim rstTableData Const adVarChar = 200 Const adInteger = 3 Const adDate = 7 ' Table Building Vars Dim intTableWidth, intTableHeight Dim intWidthLooper, intHeightLooper Dim intPageCount Dim intCurrentPage Dim blnOutOfData Dim I ' Read in parameters + set defaults if none entered. ' You could save chosen values to a DB or cookies or whatever, but it ' all sort of depends on what you're using the script for. intTableWidth = CInt(Request.QueryString("width")) If intTableWidth <= 0 Then intTableWidth = 2 intTableHeight = CInt(Request.QueryString("height")) If intTableHeight <= 0 Then intTableHeight = 4 intCurrentPage = CInt(Request.QueryString("page")) ' Make up some sample data to display. I'm using an in-memory recordset ' simply to keep things fast and because I assume most users will be using ' this script with some sort of database. This way you should just be ' able to drop in your own DB code and edit the display section and you ' should have everything working pretty quickly. Set rstTableData = Server.CreateObject("ADODB.Recordset") rstTableData.Fields.Append "id", adInteger rstTableData.Fields.Append "title", adVarChar, 25 rstTableData.Fields.Append "description", adVarChar, 255 rstTableData.Fields.Append "image", adVarChar, 255 rstTableData.Open For I = Asc("A") To Asc("Z") rstTableData.AddNew rstTableData.Fields("id").Value = I - 64 rstTableData.Fields("title").Value = "The Letter " & Chr(I) rstTableData.Fields("description").Value = "This is an image of an upper case " & Chr(I) & "." rstTableData.Fields("image").Value = "images/lb_" & Chr(I) & ".gif" rstTableData.Update Next 'I ' Display table using parameters for table size and page # and using data from recordset. ' Calculate # of pages - Divide items by page size and find the next largest whole number. intPageCount = -(Int(-(rstTableData.RecordCount / (intTableWidth * intTableHeight)))) ' Sorry for the above line... it doesn't make much logical sense, but it was the easiest ' one line implementation I could come up with. There must be a more logical one... ' and no it's not Int(...) + 1 ' If page size is larger then # of records, reset page count to 1 If intTableWidth * intTableHeight >= rstTableData.RecordCount Then intPageCount = 1 ' If current page falls outside acceptable range, default to page 1 If 0 >= intCurrentPage Or intCurrentPage > intPageCount Then intCurrentPage = 1 ' Move into recordset the appropriate number of pages rstTableData.MoveFirst rstTableData.Move (intCurrentPage - 1) * (intTableWidth * intTableHeight) ' Show our table Response.Write "
"
'Response.Write rstTableData.Fields("id").Value
Response.Write "" & rstTableData.Fields("title").Value & " " Response.Write " | " & vbCrLf
rstTableData.MoveNext
Else
' Out of data... bail out of cells early!
blnOutOfData = True
Exit For
End If
Next
' Clean up odd table cells if any and bail out of rows!
If blnOutOfData Then
If rstTableData.RecordCount Mod intTableWidth > 0 And intHeightLooper > 1 Then
For I = (rstTableData.RecordCount Mod intTableWidth) + 1 To intTableWidth
Response.Write "" & vbCrLf Next ' I End If Response.Write " |
A few sample ways you can let users adjust the display:
or
Width: <% For I = 1 To 5 Response.Write "" & I & "" & vbCrLf Next %>