效率高的分页

发布时间:2007-09-29 15:29:00 阅读:1062次

conn.asp

<%
Response.CodePage=65001
Response.Charset="utf-8"
%>
<%
set cn=server.createobject("adodb.connection")
cn.open "provider=microsoft.jet.oledb.4.0;data source="&server.mappath("db.mdb")
%>
function.asp

<%
function HTMLEncode(fString)
if not isnull(fString) then
    fString = replace(fString, ">", "&gt;")
    fString = replace(fString, "<", "&lt;")
    fString = Replace(fString, CHR(32), "&nbsp;")
    fString = Replace(fString, CHR(9), "&nbsp;")
    fString = Replace(fString, CHR(34), "&quot;")
    fString = Replace(fString, CHR(39), "&#39;")
    fString = Replace(fString, CHR(13), "")
    fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
    fString = Replace(fString, CHR(10), "<BR> ")
    HTMLEncode = fString
end if
end function
%>

<%
Sub PageControl(iCount,pagecount,page,table_style,font_style)
'生成上一页下一页链接
    Dim query, a, x, temp
    action = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME")

    query = Split(Request.ServerVariables("QUERY_STRING"), "&")
    For Each x In query

        a = Split(x, "=")
        If StrComp(a(0), "page", vbTextCompare) <> 0 Then
            temp = temp & a(0) & "=" & a(1) & "&"
        End If 
    Next

 keyw = Request.Form("keywords")
 if keyw<>"" then
  temp = "keywords="&keyw&"&"&temp
 end if
    Response.Write("<table " & Table_style & ">" & vbCrLf )       
    Response.Write("<form method=get onsubmit=""document.location = '" & action & "?" & temp & "Page='+ this.page.value;return false;""><TR>" & vbCrLf )
    Response.Write("<TD align=right>" & vbCrLf )
    Response.Write(font_style & vbCrLf )   
       
    if page<=1 then
        Response.Write ("首页 " & vbCrLf)       
        Response.Write ("上页 " & vbCrLf)
    else       
        Response.Write("<A HREF=" & action & "?" & temp & "Page=1>首页</A> " & vbCrLf)
        Response.Write("<A HREF=" & action & "?" & temp & "Page=" & (Page-1) & ">上页</A> " & vbCrLf)
    end if

    if page>=pagecount then
        Response.Write ("下页 " & vbCrLf)
        Response.Write ("尾页 " & vbCrLf)           
    else
        Response.Write("<A HREF=" & action & "?" & temp & "Page=" & (Page+1) & ">下页</A> " & vbCrLf)
        Response.Write("<A HREF=" & action & "?" & temp & "Page=" & pagecount & ">尾页</A> " & vbCrLf)           
    end if

    Response.Write(" 页次:" & page & "/" & pageCount & "页" &  vbCrLf)
    Response.Write(" 共有 " & iCount & " 条信息" &  vbCrLf)
    Response.Write(" 转到" & "<INPUT class=box TYEP=TEXT NAME=page SIZE=1 Maxlength=5 VALUE=" & page & ">" & "页"  & vbCrLf & "<INPUT type=submit style=""font-size: 9pt"" value=GO class=bt>")
    Response.Write("</TD>" & vbCrLf )               
    Response.Write("</TR></form>" & vbCrLf )       
    Response.Write("</table>" & vbCrLf )       
End Sub
%>

index.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!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=utf-8" />
<title>不错的分页</title>
</head>
<!--#include file="conn.asp"-->
<!--#include file="function.asp"-->
<body>
<table width="92%" border="0" align="center" cellpadding="2" cellspacing="0">
<%
sql = "select *from information where classid=8 order by orderid desc,id desc"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,cn,1,1
if  (rs.eof or rs.bof) then
Response.Write("<tr><td colspan=6 align=left>暂时没有些类信息</td></tr>")
else
rs.PageSize =14'每页记录条数
iCount=rs.RecordCount '记录总数
iPageSize=rs.PageSize
maxpage=rs.PageCount
page=request("page")
if Not IsNumeric(page) or page="" then
page=1
else
page=cint(page)
end if
if page<1 then
page=1
elseif  page>maxpage then
page=maxpage
end if
rs.AbsolutePage=Page
if page=maxpage then
x=iCount-(maxpage-1)*iPageSize
else
x=iPageSize
end if
For i=1 To x
%>
<tr <%if i mod 2=0 then%> bgcolor="#f3f3f3" <%end if%>>
<td width="592" height="24">
<%=rs("project")%>
</td>
<td width="305">

<%=rs("datetime")%>
<%=htmlencode("<font color=red>htmlendcode</font>")%>
</td>
</tr>
<tr>
<td height="5" colspan="2" align="left"><div style="border-top:1px dashed #CCCCCC;"></div></td>
</tr>
<%
rs.movenext
next
Response.Write("<tr bgColor='#ffffff'><td colspan=7>")
call PageControl(iCount,maxpage,page,"border=0 align=right","<p align=right>")
Response.Write("</td></tr>")
end if
rs.close
%>
</table>
</body>
</html>
 

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:效率高的分页 出自老鄢博客 | 欢迎分享