I use ASP write m row n column function, dynamic output CREATE TABLE ranks _ Application skills

Source: Internet
Author: User
There is no way to recycle TD within the normal loop TR, so there is no count of the last page of the recordset.
However, when the recordset is not enough, the same can automatically fill empty line columns, if there is insufficient please point out, thank you.
The use method is simple:

Copy Code code as follows:

<%
ShowData ("Query Language name")
Call Pagehead (number of rows, number of columns)
'-------------------------------------------------------------------------------
You can write the following Response.Write () into a function to see a personal hobby.
Response.Write (formatcrtable (table width, table height))
Response.Write (Pagefoot ())
Call Closedata ()
%>

The functions are as follows:



Copy Code code as follows:

<%
'-------------------------------------------------------------------------------
' Copyright by Jorkin.all Rights Reserved
'-------------------------------------------------------------------------------
Public RS
Public pageno,cols,rows,maxpageno,maxredcount,maxpagesize
'-------------------------------------------------------------------------------
Public Function ShowData (sqlstrings)
Set rs=server.createobject ("ADODB. Recordset ")
Rs.Open sqlstrings,oconn,1,3
End Function
Public Function Closedata ()
Rs.close
Set rs=nothing
End Function
' Initialize paging
' MaxRows = maximum number of rows
' Maxcols = maximum number of columns
'-------------------------------------------------------------------------------
Public Function Pagehead (maxrows,maxcols)
'-------------------------------------------------------------------------------
Rows=maxrows
Cols=maxcols
Maxpagesize=1
Maxredcount=0
Maxpageno=0
Pageno=0
'-------------------------------------------------------------------------------
Maxredcount = Rs.recordcount
If Maxredcount>0 Then
MaxPageSize = Rows*cols
Maxpageno = Cint ((maxredcount+maxpagesize-1)/maxpagesize)
Rs.pagesize = MaxPageSize
Pageno=request ("PageNo")
If IsEmpty (PageNo) or not IsNumeric (PageNo) or CInt (PageNo) <1 or CInt PageNo (>rs.pagecount) Then
Pageno=1
End If
Rs.absolutepage=pageno
End If
On Error Resume Next
End Function
' End of page function
' No parameters
'-------------------------------------------------------------------------------
Public Function Pagefoot ()
Strr= "<table width=" "border=" "0" "cellpadding=" "0" "cellspacing=" "0" ">" & VbCrLf
strr=strr& "<tr>" & VbCrLf
strr=strr& "<td valign=" "Top" "><div align=" "Right" ">"
' More than 1 pages will display the first page and previous (optional)
' If pageno>1 Then
strr=strr& "<a href=" "Pageno=1" "title=" "Home" "><font face = webdings>9</font></a>"
strr=strr& ""
strr=strr& "<a href=" "pageno=" &pageno-1& "" title= "" prev "" ><font face = Webdings>7</font ></a> "
' End If
strr=strr& "" &pageno& ""
' Less than the maximum number of pages will show the next page and last (optional)
' If Pageno<maxpageno Then
strr=strr& "<a href=" "pageno=" &pageno+1& "" title= "" Next page "" ><font face = Webdings>8</font ></a> "
strr=strr& ""
strr=strr& "<a href=" "pageno=" &maxpageno& "" title= "" "" ><font face = Webdings>:</font ></a> "
' End If
strr=strr& ""
strr=strr& (pageno-1) *maxpagesize+1& "/" &maxredcount& "record"
strr=strr& ""
strr=strr&pageno& "/" &maxpageno& "page"
strr=strr& "</div></td>" & VbCrLf
strr=strr& "</tr>" & VbCrLf
strr=strr& "</table>"
Pagefoot=strr
End Function
' Row and column formatting functions
' Tablewidth = table width
' Tableheight = table height (may not be valid due to browser differences)
'-------------------------------------------------------------------------------
Public Function formatcrtable (tablewidth,tableheight)
Dim I,STRR
I=0
Strr= ""
strr=strr& "<table width=" "&TableWidth&" "border=" "0" "cellspacing=" "0" "cellpadding=" "0" ">" & VbCrLf
strr=strr& "<tr>" & VbCrLf
If maxredcount>0 Then
Do While I<maxpagesize
I=i+1
If not rs.eof Then
strr=strr& "<td width=" "" &TableWidth/Cols& "" "height=" "&Tableheight/Rows&" "" > Records are output </td> "& VbCrLf
Rs.movenext
Else
strr=strr& "<td width=" "&TableWidth/Cols&" "height=" "&Tableheight/Rows&" "> Recordset Insufficient </td> "& VbCrLf
End If
If I Mod Cols = 0 Then
strr=strr& "</tr>" & VbCrLf
strr=strr& "<tr>" & VbCrLf
End If
Loop
Else
strr=strr& "<td height=" "&TableWidth&" "valign=" "Top" > No recordset </td> currently available
End If
strr=strr& "</tr>" & VbCrLf
strr=strr& "</table>" & VbCrLf
Formatcrtable=strr
End Function
%>
The code still has a lot of deficiencies, and write is not very rigorous, laughed at.
Can later be changed to class
turn from: http://jorkin.reallydo.com/article.asp?id=15
Related Article

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.