最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp文章通用分页函数
时间:2022-07-02 23:11:47 编辑:袖梨 来源:一聚教程网
<%
'------------------------------------------------------------
'------------------------------------------------------------
CLASS pagination
PUBLIC pageSize '每页显示多少记录
PUBLIC absolutePage '当前页
PUBLIC baseURL '要跳转的页面的URL
PUBLIC baseQueryString '页面原有的queryString
PUBLIC rst '转换后的记录集
PUBLIC pageListCount '下面列出来多少个页面的。。。
PUBLIC beginPosition '记录从哪里开始
PUBLIC endPosition '
PUBLIC pageListForReturn 'add by jeanun 2008.11.13
PRIVATE sub class_initialize '构造函数。
pageSize =20
absolutePage=request.QueryString("page")
baseURL =request.ServerVariables("URL")
baseQueryString =""
set rst=server.CreateObject("ADODB.RecordSet")
pageListCount =10
dim o
for each o in request.querystring
if o<>"page" then
baseQueryString= baseQueryString & o & "=" & request.querystring(o) & "&"
end if
next
if not isNumeric(absolutePage) then
absolutePage = 1 '不能和下面的判断条件合并在一起,要不然,会提示出错,想不通!
end if
if trim(absolutePage)="" or absolutepage<=0 then
absolutePage =1 '注,不是从0开始的。不信可以试试。
end if
absolutePage=cint(absolutepage)
end sub
PUBLIC SUB setValue(pRst)
set rst=pRst
rst.pageSize =pageSize
if Cint(absolutepage)>rst.pagecount then
absolutepage=rst.pagecount
end if
if not rst.eof then
rst.absolutePage=absolutePage
beginPosition =rst.absoluteposition
else
beginPosition =0
end if
endPosition =beginPosition+pagesize-1
if endPosition>rst.recordcount then
endPosition=rst.recordcount
end if
END SUB
PUBLIC SUB pageList
if rst.recordcount>0 then
dim startNum
startNum=int((absolutePage-1)/pageListCount)*pageListCount+1
'公式:int((n-1)/col)*col+1 n给定的参数 col每行显示几个数字 从1开始,顺序排
if absolutepage<>1 then
response.write("|<")
end if
if startNum-pageListCount>0 then
response.write("<<")
end if
for i=startNum to startNum+pageListCount-1
if i=absolutepage then
className="activePage"
else
className="inactivePage"
end if
response.write(""&i&"")
if i>=rst.pageCount then
exit for
end if
Next
if startNum+pageListCount<=rst.pageCount then
response.write(">>")
end if
if absolutepage<>rst.pagecount then
response.write(">|")
end if
END IF
End Sub
Public Sub pageList4Return
if rst.recordcount>0 then
dim startNum
startNum=int((absolutePage-1)/pageListCount)*pageListCount+1
'公式:int((n-1)/col)*col+1 n给定的参数 col每行显示几个数字 从1开始,顺序排
if absolutepage<>1 then
pageListForReturn = "|<"
end if
if startNum-pageListCount>0 then
pageListForReturn = pageListForReturn & "<<"
end if
for i=startNum to startNum+pageListCount-1
if i=absolutepage then
className="activePage"
else
className="inactivePage"
end if
pageListForReturn = pageListForReturn & ""&i&""
if i>=rst.pageCount then
exit for
end if
Next
if startNum+pageListCount<=rst.pageCount then
pageListForReturn = pageListForReturn & ">>"
end if
if absolutepage<>rst.pagecount then
pageListForReturn = pageListForReturn & ">|"
end if
pageListForReturn = pageListForReturn & " Go!"
END IF
END Sub
END CLASS
%>
调用上面分页类型的方法
共 <%=myPagination.rst.recordcount %> 条记录 当前 <%=myPagination.absolutepage%>/<%=myPagination.rst.pagecount%> 页 <% myPagination.pageList %> |