ASP implements dynamic generation of rows and columns of tables in a Web page

Source: Internet
Author: User
Dynamic | Web page

Sometimes, you need to put a certain number of words and pictures in a table column, and need to dynamically display the number of rows and columns, such as 4 pictures in a row or 5 pictures, sometimes it is difficult to judge the end of TR or TD with a table, where I wrote a piece of code, Can judge the end position of the ranks in real time, and automatically add the empty TR and TD when the data in the recordset is insufficient.

Test table

' Create Table Test (ID int,stitle varchar (50))

Program code

' Test row 4 columns, row four rows
Dim i,j
Dim irscount,irows
Dim perlines
Perlines=4 ' Number of columns to display per line
Set Objrs=server. CreateObject ("Adodb.recordset")
Objrs.open "SELECT top * from Test ORDER by id", conn,3,1
If not objrs.eof Then
Response.Write "<table width=" "100%" "cellpadding=" "0" "cellspacing=" "8" ">" &vbcrlf
Irscount=objrs.recordcount ' Get the actual number of records
Irows=int (Irscount/perlines) ' calculates the number of rows available
If Irows<1 Then
Irows=1
Else
If Irscount mod perlines=0 then
Irows=int (Irscount/perlines)
Else
Irows=int (Irscount/perlines) +1
End If
End If
I=1
While Not objrs.eof
For I=1 to Irows
Response.Write "<tr>" &vbcrlf
For J=1 to Perlines
If Not objRS.EOF Then
Response.Write "<td width=" "25%" "><div align=" "Center" ">" &objrs ("Stitle") & "</div></" Td> "&vbcrlf
Else
Response.Write "<td> </td>" &vbcrlf
End If
If not objrs.eof then Objrs.movenext
Next
Response.Write "</tr>" &vbcrlf
Next
Wend
Response.Write "</table>"
End If
Objrs.close
Set objrs=nothing



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.