您的位置是: 软件 > 设计在线 > 网页陶吧 > 技术平台 > HTML学习 > 正文 查cseek报价

用ASP做一个分页程序
2000-05-31作者: wodeail出处: CPCW
我对此感兴趣
订阅电子杂志
发表评论
advertisement
热点推荐
· 群雄逐鹿 十四种Java开发工具点评
· 网文快捕,将网络资源搬回家
· Windows系统瘦身计划
· PS多媒体教程带你享受快乐学习
· 网络游戏外挂设计深度探索
· 武装你的桌面,桌面工具大阅兵
天极搜索引擎服务
资讯  产品  经销商  下载  社区

 ∧闶欠裎四愕恼镜阄恼鹿喽锤醋隽唇由弦灰场⑾乱灰痴庑┓乘龅墓ぷ鞣⒊钅兀肯衷谟辛薃SP,只要你的主页支持ASP,你就可以很简单的实现对文章的管理了,排序、链接、显示这些工作都让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$#@62;"&totalnumber&"$#@60;/b$#@62;篇文章 $#@60;b$#@62;"&maxperpage&"$#@60;/b$#@62;篇文章/页$#@60;/font$#@62;"

response.write " $#@60;font color=#000080$#@62;转到:$#@60;/font$#@62;$#@60;input type=text name=page size=4 maxlength=10 class=smallInput value="¤tpage&"$#@62;"

response.write "$#@60;input class=buttonface type=submit value= Goto name=cndok$#@62;$#@60;/span$#@62;$#@60;/p$#@62;$#@60;/form$#@62;"

end function

$#@62;

  以上代码很简单的就实现了ASP网页的多种分页功能,不论是对浏览者还是管理者都能很方便的浏览和管理,我只在相关部分作了一些解释,象这个ASP程序还必须有数据库的支持才可以,关于数据库的问题我就不详述了,具体的实例大家可以看看我的主页(http://aasp.yeah.net)上的文章管理程序,另外还有具体的程序下载!


【责任编辑:】
推荐给朋友我想参加相关培训打印我对此感兴趣订阅电子杂志发表评论

天极商业街
·激情美女让你想入非非
·图铃梦工厂下载无限!
·找寻童真,卡通专题
·夏日激情交友社区!
·星座运程,预测人生
CSEEK搜索
相关内容阅读排行榜
  • XBOX模拟器模拟《Halo》的截图
  • 将多种音乐格式转换为MP3
  • 《反恐精英》服务器搜索软件教程
  • 咕噜咕噜内测,十大系统揭密
  • 忍一时风平浪静 退一步海阔天空
  • 《育成足球04》金手指(PS2)
  • 《异域传说二部曲》金手指(PS2)
  • 等待是一种美丽

  • advertisement

     短信乐园
    好名好运 每日运程 姓名配对 情侣缘分 生命曲线 三生三世 自我认知 前世今生
    游戏嘉年华 爱情宝石 魔法水晶 麻辣竞猜 魔法占卜 暗恋表白 星座运程 浮生记


    · 至少还有你-林忆莲
    · 东风破-周杰伦
    · 什么都不怕-杨千桦
    · 下一站天后-Twins
    · 不羁的风-张国荣
    · 帅哥接电话
    · 严守一标准铃声
    · 0.01公分
    · 下雨收衣服啦
    · 快点接我电话吧

    欲望都市 成人笑话 图铃包月 天气预报 麻辣生活 都市报
    体育新闻 娱乐新闻 点歌祝福 情人悄悄话