首页 电脑 电脑学堂 查看内容

ASP 分页技巧

2006-4-24 15:16 670 0

摘要: 主文件 nclass.asp包含文件 top.asp || bottom.asp || abbrword.asp || conn.asp 内容 ---/----------------------...
关键词: nbsp Response asp pageview nclassid Write articleid classid rsn Request

主文件 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<[email protected]>                                                                                                        '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, 返回值1If 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, 默认为 1If 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 "&nbsp;"  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 %>  &nbsp; <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 %> &nbsp; <% showPageNavi rsn.PageCount,pageview %>  &nbsp; <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 %>&nbsp; <%= 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 linkDim siteinfoHomelinkDim siteinfoHomelink_numRows Set siteinfoHomelink = Server.CreateObject("ADODB.Recordset")siteinfoHomelink.ActiveConnection = MM_conn_STRINGsiteinfoHomelink.Source = "SELECT * FROM siteinfo"siteinfoHomelink.CursorType = 0siteinfoHomelink.CursorLocation = 1siteinfoHomelink.LockType = 1siteinfoHomelink.Open() siteinfoHomelink_numRows = 0 homeurl=siteinfoHomelink.Fields.Item("siteurl").Valuesitename=siteinfoHomelink.Fields.Item("sitename").Valuehome = "<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 rsSiteinfoDim rsSiteinfo_numRows Set rsSiteinfo = Server.CreateObject("ADODB.Recordset")rsSiteinfo.ActiveConnection = MM_conn_STRINGrsSiteinfo.Source = "SELECT * FROM siteinfo"rsSiteinfo.CursorType = 0rsSiteinfo.CursorLocation = 1rsSiteinfo.LockType = 1rsSiteinfo.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)%>&nbsp;<%= siteAdmin_ %><a href="">mailto:<%=(rsSiteinfo.Fields.Item("siteadminemail").Value)%>"><%=(rsSiteinfo.Fields.Item("siteadmin").Value)%></div><%rsSiteinfo.Close()Set rsSiteinfo = Nothing%> ---/----------------------------------------------------------- abbrword.asp <% 'Site InfomationsiteName_="绿色学院 Green Institute"siteUrl_="http://gi.2288.org:88/" 'General wordwelcomeShort_="欢迎光临"siteAdmin_="站长: "siteFoundtime_="开站日期: "homeurl_="首页" ' errorerror_="<center>页面 ID 出错, 或文章已删除</center>"errorA_="<center>文章 ID 出错</center>"errorN_="没有该篇"nothing_="没有了"nodata_="<center>没有数据</center>" 'page wordprevious1_="上一"next1_="下一" previous_=" 上页"next_=" 下页"previousP_=" 上页"nextP_=" 下页"previous10_=" 上十"next10_=" 下十" previousA_=" 上篇"nextA_=" 下篇" previousD_=" 上一天"nextD_=" 下一天" previousY_="上年"nextY_="下年" previousW_="上星期"nextW_="下星期" today_="今天" 'Articles ColumncolumnClass_="主类: "columnNclass_="子类: " 'descript worltitle_="标题"article_="文章" 'Category worldhotHits_="热门文章"coldHits_="冷门文章"newA_="最近更新"show_="显示"showAll_="所有文章" ' page articles.asptext_="正文"hitsUp1_="点击: "source_="来源: "author_="作者: "postDate_="发表日期: "sourceColumn_="所属栏目: "pagelink_="页面链接: "text_="正文: "fashion_=" 热门" ' page nclass.aspnc1_="nclass.asp?classid="nc2_="&nclassid="nc3_="&pageview="pageNum_="页数"articleNum_="篇数" ' page dateview.aspdat1="dateview/dateview.asp?dayview="dat2="dateview.asp?dayview="dv_=request.QueryString("dayview")dvP1_=year(dv_)&"-"&month(dv_)&"-"&day(dv_)+1dvM1_=year(dv_)&"-"&month(dv_)&"-"&day(dv_)-1 ' page yearview.aspyvE_="<center>没有该年份的数据</center>" ' page monthview.asppreviousM_="上月"nextM_="下月" ' page weekview.aspweekA_="所属星期"week_="星期" ' page todayview.asptvv_="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="&articleidt1_="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_STRINGMM_conn_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("/data/data.mdb")%> ---/-----------------------------------------------------------
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部