用ASP做一个分页程序

2016-01-29 19:56 15 1 收藏

用ASP做一个分页程序,用ASP做一个分页程序

【 tulaoshi.com - ASP 】

请看以下实现ASP分页程序的代码:

$#@60;anguage="vbscript"

dim conn

dim connstr

dim totalPut

dim CurrentPage

dim TotalPages

dim i,j

dim sql

dim rs

on error resume next

打开数据库

connstr="DBQ="+server.mappath("book.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"

set conn=server.createobject("ADODB.CONNECTION")

conn.open connstr

set rs=server.createobject("adodb.recordset")

定义每页文章显示数

const MaxPerPage=18

if not isempty(request("page")) then

currentPage=cint(request("page"))

else

currentPage=1

end if

sql="select * from learning order by articleid desc"

Set rs= Server.CreateObject("ADODB.Recordset")

rs.open sql,conn,1,1

if rs.eof and rs.bof then

response.write "$#@60;p align=center$#@62; 还 没 有 任 何 文 章$#@60;/p$#@62;"

else

数据库中文章数totalput

totalPut=rs.recordcount

if currentpage$#@60;1 then

currentpage=1

end if

统计总页数currentpage

if (currentpage-1)*MaxPerPage$#@62;totalput then

if (totalPut mod MaxPerPage)=0 then

currentpage= totalPut MaxPerPage

else

currentpage= totalPut MaxPerPage + 1

end if

end if

if currentPage=1 then

showpage totalput,MaxPerPage,"index.asp"

showContent

showpage totalput,MaxPerPage,"index.asp"

else

if (currentPage-1)*MaxPerPage$#@60;totalPut then

rs.move (currentPage-1)*MaxPerPage

dim b mark

bookmark=rs.bookmark

showpage totalput,MaxPerPage,"index.asp"

showContent

showpage totalput,MaxPerPage,"index.asp"

else

currentPage=1

showpage totalput,MaxPerPage,"index.asp"

showContent

showpage totalput,MaxPerPage,"index.asp"

end if

end if

rs.close

end if

set rs=nothing

conn.close

set conn=nothing

sub showContent

dim i

i=0

do while not rs.eof

$#@62;

选择显示数据库内容

$#@60;a href="openarticle.asp?id=$#@60;=rs("articleid")$#@62;"$#@62;$#@60;=rs("title")$#@62;$#@60;/a$#@62;[点击:$#@60;=rs("hits")$#@62;]$#@60;br$#@62;

$#@60;

当显示记录大于maxperpage时结束这页

i=i+1

if i$#@62;=MaxPerPage then exit do

rs.movenext

loop

end sub

function showpage(totalnumber,maxperpage,filename)

求出当每页18篇文章时总共的页数

dim n

if totalnumber mod maxperpage=0 then

n= totalnumber maxperpage

else

n= totalnumber maxperpage+1

end if

response.write "$#@60;form method=Post action="&filename&"$#@62;"

response.write "$#@60;p align=center$#@62;$#@60;font color=#000080$#@62;$#@62;$#@62;分页$#@60;/font$#@62; "

显示页数链接的条件

if CurrentPage$#@60;2 then

response.write "$#@60;font color=#000080$#@62;首页 $#@60;/font$#@62; "

else

response.write "$#@60;a href="&filename&"?page=1&$#@62;首页$#@60;/a$#@62; "

response.write "$#@60;a href="&filename&"?page="&CurrentPage-1&"$#@62;$#@60;/a$#@62; "

end if

if n-currentpage$#@60;1 then

response.write "$#@60;font color=#000080$#@62; 尾页$#@60;/font$#@62;"

else

response.write "$#@60;a href="&filename&"?page="&(CurrentPage+1)

response.write "$#@62;$#@60;/a$#@62; $#@60;a href="&filename&"?page="&n&"$#@62;尾页$#@60;/a$#@62;"

end ifc

response.write "$#@60;font color=#000080$#@62; 页次:$#@60;/font$#@62;$#@60;strong$#@62;$#@60;font color=red$#@62;"&CurrentPage&"$#@60;/font$#@62;$#@60;font color=#000080$#@62;/"&n&"$#@60;/strong$#@62;页$#@60;/font$#@62;"

response.write "$#@60;font color=#000080$#@62; 共$#@60;b$

来源:http://www.tulaoshi.com/n/20160129/1510423.html

延伸阅读
标签: PHP
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN" <HTML <HEAD <TITLEPaging Test</TITLE <META NAME="Generator" CONTENT="TextPad 4.0" <META NAME="Author" CONTENT="?" <META NAME="Keywords" CONTENT="?" <META NAME=&...
标签: ASP
  newDoc.asp      ----------------------------------------------------------      <%@ Language=VBScript %      <SCRIPT id=DebugDirectives runat=server language=javascript      // Set these to true to enable d...
效果图: 制作教程:
平时的工作很忙,只有买花的时间,买花瓶的时间则抽不出来了,而又不想马马虎虎的买一个来将就,想来想去还是自己亲手做一个吧,即是自己的劳动成果,还可以根据自己的爱好自己制作心中的所爱。于是就用一些铁丝的麻绳自己做了一个,呵呵,乱想出来的,虽然有一些简陋,不过还是蛮有味道的,效果用艺术的眼光看或许会好看些。把你的想象力和灵...
标签: Web开发
使用这个存储过程可以实现分页的,新手可以看看哦! create proc proPage(@pageid int ,@pagesize int) as begin if (@pageid=1) begin  set rowcount @pagesize  select * from test order by id end else begin  declare @no1 int  declare @num int  sel...

经验教程

170

收藏

37
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部