ASP 分页技巧 BY Stabx
2006-4-19
效果
首页 上十 上一 1 2 3 4 5 6 7 8 9 10 下一 下十 尾页 转到___
页数:1/25页 篇数:125
主文件 nclass.asp
包含文件 top.asp || bottom.asp || abbrword.asp || conn.asp
内容
---/-----------------------------------------------------------
nclass.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/conn.asp" -->
<%
'subject : ASP 分页技巧
'author : Stabx<shawl.qiu@gmail.com>
'blog : http://btbtd.exblog.jp/ / http://my.opera.com/btbtd/
'blog name : Phoenix.GI - P.GI
'date : 2006-4-19
' rsn.PageCount / 总页数
' pageview / 当前页数
Dim I '定义循环变量
Dim RPP 'RPP:指定每页显示的记录数,
Dim pageview '翻页变量
I=1 '从 1 开始
RPP=50 '每页显示 50 条记录
pageview=CInt(Request("pageview")) '读取 URL 页号
Dim rsn '定义链接名
Set rsn = Server.CreateObject("ADODB.Recordset") '建立一个 rsn 数据库查询
rsn.ActiveConnection = MM_conn_STRING '这是 DW 的链接字符串
' rsn 链接方式
rsn.Source = "SELECT * FROM article WHERE classid="&request.QueryString("classid")&" and nclassid="&request.QueryString("nclassid")&" ORDER BY articleid DESC"
' rsn 查询语句, SELECT 所有列 FROM 表 WHERE 条件 ORDER BY 条件
rsn.CursorType = 1 '游标属性
rsn.CursorLocation = 2 '游标位置
rsn.LockType = 1
' 定义数据库查询模式
rsn.Open()
' 打开数据库链接
if not rsn.eof then '显示不为空的数据
end if
rsn.PageSize=RPP
' 定义每页显示记录数
If pageview<=0 Then pageview=1 '如果 pageview 小于或等于0, 返回值1
If pageview>rsn.PageCount Then pageview=rsn.PageCount ' 如果 pageview 大于分页总数, 返回分页末页值
rsn.AbsolutePage=pageview '定义当前页码
Sub ShowPageInfo(tPageCount,cPageNo) '定义子例程 ShowPageInfo, 显示页数和总页
Response.Write cPageNo&"/"&tPageCount&"页" '显示当前页和总页数
End Sub
Sub ShowPageNavi(tPageCount,cPageNo)
' 定义子例程 ShowPageNavi, 显示分页号
If cPageNo<1 Then cPageNo=1
' 如果页数小于 1, 默认为 1
If tPageCount<1 Then tPageCount=1
If cPageNo>tPageCount Then cPageNo=tPageCount
Dim NaviLength
NaviLength=10 ' 显示数字链接个数
Dim I,StartPage,EndPage ' 定义当前页, 开始页, 结束页
StartPage=(cPageNo\NaviLength)*NaviLength+1 '为开始页赋值
if pageview=1 then '判断是否首页, 如果是首页不添加链接,反之添加.
Response.Write "<font color=""#CCCCCC"">首页</font> " '显示没有添加链接热点的"首页"
Else
Response.Write "<a href="&nc1_&rqsc_&nc2_&rqsnc_&nc3_&"1>首页</a> " '首页链接
End If
If (cPageNo Mod NaviLength)=0 Then StartPage=StartPage-NaviLength
EndPage=StartPage+NaviLength-1
If EndPage>tPageCount Then EndPage=tPageCount
If StartPage>1 Then '向后移动一分页, 十页为一分页
Response.Write "<a href="&nc1_&rqsc_&nc2_&rqsnc_&nc3_&(cPageNo-NaviLength)&">"&previous10_&"</a> "
Else
Response.Write "<font color=""#CCCCCC"">"&previous10_&"</font> "
End If
If pageview <> 1 and pageview <>0 Then '后移一页
Response.Write "<a href="&nc1_&rqsc_&nc2_&rqsnc_&nc3_&(pageview-1)&">"&previous1_&"</a> "
Else
Response.Write "<font color=""#CCCCCC"">"&previous1_&"</font> "
End If
For I=StartPage To EndPage
If I=cPageNo Then
Response.Write "<b>"&I&"</b>"
Else
Response.Write "<a href="&nc1_&rqsc_&nc2_&rqsnc_&nc3_& I & ">" & I & "</a>"
End If
If I<>tPageCount Then Response.Write " "
Next
If pageview <> rsn.PageCount and pageview <>0 Then '前移一页
Response.Write " <a href="&nc1_&rqsc_&nc2_&rqsnc_&nc3_&(pageview+1)&">"&next1_&"</a> "
Else
Response.Write "<font color=""#CCCCCC"">"&next1_&"</font> "
End If
If EndPage<tPageCount Then '向后移动一分页, 十页为一分页
Response.Write " <a href="&nc1_&rqsc_&nc2_&rqsnc_&nc3_&(cPageNo+NaviLength)&">"&next10_&"</a> "
Else
Response.Write " <font color=#CCCCCC>"&next10_&"</font> "
End If
if rsn.PageCount<>pageview then '判断是否尾页
Response.Write "<a href="&nc1_&rqsc_&nc2_&rqsnc_&nc3_&rsn.PageCount&">尾页</a>"
Else
Response.Write "<font color=""#CCCCCC"">尾页</font>"
End If
End Sub
%>
<!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>Untitled Document</title>
</head>
<body>
<!--#include virtual="top.asp"-->
<div class="c"</div>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<div CLASS="center">
<form NAME="pageform" ID="pageform">
<% showPageNavi rsn.PageCount,pageview %>
<select NAME="menu1" onChange="MM_jumpMenu('parent',this,0)">
<% for i=1 to rsn.PageCount %>
<option VALUE="<%="nclass.asp?classid="&rqsc_&"&nclassid="&rqsnc_&"&pageview="&i%>"
<% if pageview=i then%> selected <%end if%>>
第<%=i%>页
</option>
<%next%>
</select>
</form>
</div>
<%
If rsn.EOF OR rsn.BOF Then
Else
For I=1 To RPP
%>
<!-- <%=(pageview-1)*RPP+I%> -->
<p/>
<%=rsn("dateandtime")%> <a href="<%=t1_&rsn("classid")&t2_&rsn("nclassid")&t3_&rsn("articleid")%>"><%= rsn("title") %></a>
<%
rsn.MoveNext
If rsn.EOF OR rsn.BOF Then Exit For
Next
End If
%>
<div CLASS="center">
<form NAME="pageform" ID="pageform">
<% showPageInfo rsn.PageCount,pageview %>
<% showPageNavi rsn.PageCount,pageview %>
<select NAME="menu1" onChange="MM_jumpMenu('parent',this,0)">
<% for i=1 to rsn.PageCount %>
<option VALUE="<%="nclass.asp?classid="&rqsc_&"&nclassid="&rqsnc_&"&pageview="&i%>"
<% if pageview=i then%> selected <%end if%>>
第<%=i%>页
</option>
<%next%>
</select>
</form>
<%= pageNum_ %>:<% showPageInfo rsn.PageCount,pageview %>
<%= articleNum_ %>:<% Response.Write(rsn.RecordCount) %><br/>
</div>
<!--#include virtual="bottom.asp"-->
</body>
</html>
---/-----------------------------------------------------------
top.asp
<link HREF="css.css" REL="stylesheet" TYPE="text/css">
<!--#include virtual="include/abbrword.asp"-->
<!--#include virtual="include/columnclass.asp"-->
<%
'set home link
Dim siteinfoHomelink
Dim siteinfoHomelink_numRows
Set siteinfoHomelink = Server.CreateObject("ADODB.Recordset")
siteinfoHomelink.ActiveConnection = MM_conn_STRING
siteinfoHomelink.Source = "SELECT * FROM siteinfo"
siteinfoHomelink.CursorType = 0
siteinfoHomelink.CursorLocation = 1
siteinfoHomelink.LockType = 1
siteinfoHomelink.Open()
siteinfoHomelink_numRows = 0
homeurl=siteinfoHomelink.Fields.Item("siteurl").Value
sitename=siteinfoHomelink.Fields.Item("sitename").Value
home = "<a href="&(siteinfoHomelink.Fields.Item("siteurl").Value)&">"&(siteinfoHomelink.Fields.Item("sitename").Value)&"</a>"
pageurl=homeurl&request.ServerVariables("URL")&"?"&request.ServerVariables("QUERY_STRING")
pagelink="<a href="&pgeurl&">"&pageurl&"</a>"
%>
---/-----------------------------------------------------------
bottom.asp
<%
Dim rsSiteinfo
Dim rsSiteinfo_numRows
Set rsSiteinfo = Server.CreateObject("ADODB.Recordset")
rsSiteinfo.ActiveConnection = MM_conn_STRING
rsSiteinfo.Source = "SELECT * FROM siteinfo"
rsSiteinfo.CursorType = 0
rsSiteinfo.CursorLocation = 1
rsSiteinfo.LockType = 1
rsSiteinfo.Open()
rsSiteinfo_numRows = 0
%>
<div class="center"><%=(rsSiteinfo.Fields.Item("project").Value)%> | <%=(rsSiteinfo.Fields.Item("sitecopyright").Value)%> <a href="<%=(rsSiteinfo.Fields.Item("siteurl").Value)%>"><%=(rsSiteinfo.Fields.Item("sitename").Value)%></a></div> <br />
<div class="center"><%= siteFoundtime_ %><%=(rsSiteinfo.Fields.Item("sitefoundtime").Value)%> <%= siteAdmin_ %><a href="mailto:<%=(rsSiteinfo.Fields.Item("siteadminemail").Value)%>"><%=(rsSiteinfo.Fields.Item("siteadmin").Value)%></div>
<%
rsSiteinfo.Close()
Set rsSiteinfo = Nothing
%>
---/-----------------------------------------------------------
abbrword.asp
<%
'Site Infomation
siteName_="绿色学院 Green Institute"
siteUrl_="http://gi.2288.org:88/"
'General word
welcomeShort_="欢迎光临"
siteAdmin_="站长: "
siteFoundtime_="开站日期: "
homeurl_="首页"
' error
error_="<center>页面 ID 出错, 或文章已删除</center>"
errorA_="<center>文章 ID 出错</center>"
errorN_="没有该篇"
nothing_="没有了"
nodata_="<center>没有数据</center>"
'page word
previous1_="上一"
next1_="下一"
previous_=" 上页"
next_=" 下页"
previousP_=" 上页"
nextP_=" 下页"
previous10_=" 上十"
next10_=" 下十"
previousA_=" 上篇"
nextA_=" 下篇"
previousD_=" 上一天"
nextD_=" 下一天"
previousY_="上年"
nextY_="下年"
previousW_="上星期"
nextW_="下星期"
today_="今天"
'Articles Column
columnClass_="主类: "
columnNclass_="子类: "
'descript worl
title_="标题"
article_="文章"
'Category world
hotHits_="热门文章"
coldHits_="冷门文章"
newA_="最近更新"
show_="显示"
showAll_="所有文章"
' page articles.asp
text_="正文"
hitsUp1_="点击: "
source_="来源: "
author_="作者: "
postDate_="发表日期: "
sourceColumn_="所属栏目: "
pagelink_="页面链接: "
text_="正文: "
fashion_=" 热门"
' page nclass.asp
nc1_="nclass.asp?classid="
nc2_="&nclassid="
nc3_="&pageview="
pageNum_="页数"
articleNum_="篇数"
' page dateview.asp
dat1="dateview/dateview.asp?dayview="
dat2="dateview.asp?dayview="
dv_=request.QueryString("dayview")
dvP1_=year(dv_)&"-"&month(dv_)&"-"&day(dv_)+1
dvM1_=year(dv_)&"-"&month(dv_)&"-"&day(dv_)-1
' page yearview.asp
yvE_="<center>没有该年份的数据</center>"
' page monthview.asp
previousM_="上月"
nextM_="下月"
' page weekview.asp
weekA_="所属星期"
week_="星期"
' page todayview.asp
tvv_="todayview.asp"
' URL abbr.
up1_="../"
rqsc_=request.QueryString("classid")
rqsnc_=request.QueryString("nclassid")
rqs_=request.QueryString("articleid")
rqsdv_=request.QueryString("dayview")
articleid_="articles.asp?articleid="
articleid1_="articles1.asp?articleid="
t_="t.asp?nclassid="&nclassidSSS&"&articleid="&articleid
t1_="t.asp?classid="
t2_="&nclassid="
t3_="&articleid="
dvv_="dateview.asp?dayview="
yvv_="yearview.asp?yearview="
mvv_="monthview.asp?monthview="
wvv_="weekview.asp?weekview="
classid_="class.asp?classid="
nclassid_="nclass.asp?nclassid="
abbrid_="articles.asp?classid="&classid&"&nclassid="&nclassid&"&articleid="
abbrid1_="t.asp?classid="&classid&"&nclassid="&nclassid&"&articleid="
%>
---/-----------------------------------------------------------
conn.asp
<%
' FileName="Connection_ado_conn_string.htm"
' Type="ADO"
' DesigntimeType="ADO"
' HTTP="true"
' Catalog=""
' Schema=""
Dim MM_conn_STRING
MM_conn_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("/data/data.mdb")
%>
---/-----------------------------------------------------------