|
Jun
10
|
|
效果图:
调用:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="access.class.asp"-->
<!--#include file="pagination.class.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link href="pagination.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
function len1(a)
len1 = left(a,10) & "..."
end function
set p = new Pagination
p.template="{{title|len1}}"
p.sql = "select * from News"
p.pkey = "id"
p.cols = 2
p.page = request.QueryString("page")
p.show
%>
</body>
</html>
类代码:
<% '''''''''''''''''''''''''''''''' ' ' ' Author: pwwang ' ' Site : http://pwwang.com ' ' Version: 1.0 ' ' ' '''''''''''''''''''''''''''''''' class Pagination private pSql private pHeader private pFooter private pTemplate private pRows private pCols private pPage private pPKey private pPageCount private pRecordCount public property let pkey(value) pPKey = value end property public property let page(value) pPage = value if not isNumeric(pPage) then pPage = 1 if pPage < 1 then pPage = 1 pPage = cint(pPage) end property public property let sql(value) pSql = value db.query(value) end property public property let header(value) pHeader = value end property public property let footer(value) pFooter = value end property public property let template(value) pTemplate = value end property public property let rows(value) pRows = value end property public property let cols(value) pCols = value end property private function tempcode(i) dim t, re, re1, matches, mat, mat1, datandfun, data, fun set re = new RegExp set re1 = new RegExp t = pTemplate re.Pattern="\{\{\s*[^}]+\s*\}\}" re.global = true set matches = re.execute(t) for each mat in matches mat1 = trim(mid(mat,3,len(mat)-4)) datandfun = split(mat1, "|") if Ubound(datandfun) = 0 then data = trim(mat1) t = replace(t, mat, db.get_value2(data,i)) else data = trim(datandfun(0)) fun = trim(datandfun(1)) t = replace(t, mat, eval( fun & "(""" & db.get_value2(data, i) & """)")) end if next tempcode = t end function private function getFooter() if not pFooter then getFooter = "" else getFooter = "<table width='100%' border='0' id='pagination_footer'>" getFooter = getFooter & "<tr><td>" getFooter = getFooter & " 当前页:" & pPage & "/" & pPageCount getFooter = getFooter & " 记录数:" & pRecordCount if pPage > 1 then getFooter = getFooter & " <a href='?page=1'>首页</a> <a href='?page=" & pPage - 1 &"'>上页</a> " else getFooter = getFooter & " 首页 上页 " end if if pPage < pPageCount then getFooter = getFooter & " <a href='?page=" & pPage + 1 &"'>下页</a> <a href='?page=" & pPageCount & "'>尾页</a> " else getFooter = getFooter & " 下页 尾页 " end if getFooter = getFooter & " 跳到第<input type='text' id='gotopage' size='1' value='"&pPage&"' />页<input type='button' value='Go' onclick=""javascript:location='?page='+document.getElementById('gotopage').value"" />" getFooter = getFooter & "</td></tr></table>" end if end function private function mainloop() if isempty(pFooter) then pFooter = true if isempty(pRows) then pRows = 10 if isempty(pCols) then pCols = 1 pRecordCount = db.num_rows pPageCount = cint(pRecordCount / (pRows * pCols) + 0.5) if pPage > pPageCount then pPage = pPageCount dim pagesql, startr, endr startr = (pPage - 1) * pRows * pCols if pPage * pRows * pCols > pRecordCount then endr = pRecordCount else endr = pPage * pRows * pCols end if if pPage > 1 then pagesql = "SELECT TOP " & endr & " * FROM (" & pSql & ") WHERE " & pPKey & " NOT IN (SELECT TOP " & startr & " " & pPKey & " FROM (" & pSql & "))" else pagesql = "SELECT TOP " & pRows * pCols & " * FROM (" & pSql & ")" end if db.query(pagesql) dim i, j mainloop = "<table width='100%' border='0' cellspacing='1' id='pagination_table'>" for i = 0 to pRows - 1 if i mod 2 = 0 then mainloop = mainloop & "<tr class='odd'>" else mainloop = mainloop & "<tr class='even'>" end if for j = 0 to pCols - 1 mainloop = mainloop & "<td>" if i*pCols+j < db.num_rows then mainloop = mainloop & tempcode(i*pCols+j) else mainloop = mainloop & " " end if mainloop = mainloop & "</td>" next mainloop = mainloop & "</tr>" next mainloop = mainloop & "</table>" end function public sub show() response.write pHeader response.write mainloop response.write getFooter end sub end class %>
CSS:
#pagination_table{ background-color:#09F; font-size:12px; } #pagination_table td{ padding:4px; } #pagination_table tr.odd{ background-color:#fff; } #pagination_table tr.even{ background-color:#eee; } #pagination_footer{ text-align:center; font-size:12px; }
说明:
1. 需要调用之前发布的access操作类
2. 可以分列,单页记录数为rows和cols决定
3. 表头由参数header直接给出
4. 参数footer决定是否显示表脚(翻页链接)
5. {{parm}}用来显示数据库中这个列名对应的数据
6. {{parm|fun}}fun函数可以对这个数据进行修饰
7. 表的样式可以通过css定义,奇偶行可以定义不同的样式
RELATED POSTS:

哥,您真是闲的蛋疼,竟然去搞asp!无语。。。好好的人才就这么糟蹋了。。。
确认是蛋疼了一把