当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp+版本简单的留言板的制作(三)

ASP
ASP实例代码:搞个长文章分页代码
说说对象的复制
多个函数验证同一表单
查询某个字段没有值的所有记录的SQL语句怎么写?
ASP实例:一个简单的ASP无组件上传类
ASP实例讲解:用分页符实现长文章分页显示
ASP实例:动态网页中常用的6个ASP程序
ASP实例:词语搭配游戏的制作
ASP实例学习:随机生成文件名的函数
asp实例:测试WEB服务器
ASP实例:计数器程序详解
预防ASP网站被黑 彻底了解ASP木马
分享:XML HTTP Request的属性和方法简介
ASP架设:给每个IIS站点建立一个用户
ASP技巧:判断远程图片是否存在
故障解决:解决ASP脚本运行超时的方法
再说ASP输出N行N列表格
怎么判断一个对象是否已被释放
ASP实现网页打开任何类型文件都保存的方法
ASP技巧:利用函数InstrRev()获取当前文件名

ASP 中的 asp+版本简单的留言板的制作(三)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 23 ::
收藏到网摘: n/a

  asp+版本简单的留言板的制作(三)
/*
豆腐制作,都是精品
http://www.asp888.net 豆腐技术站
如转载,请保留版权信息
*/
现在该显示了,其实显示是很简单,只要看过豆腐前面文章的朋友应该都知道该怎么写这个程序,但是我在这里要强调的是 分页 的程序,我也和大家 一样,在开始的时候,想利用web form的数据绑定的功能,但是不幸的是,虽然用datagrid 实现绑定和分页都是很简单的,但是 datagrid显然形式上的Grid显然对 留言版 这样的程序是 不适合的,DBList 到是可以适合留言版的程序形式
但是 我查找了很长的时间 都没有找到如何去 实现分页的程序后来在 MSDN 上找到了 PagedDataSource 看看他的 Class Member 我都心惊肉跳,所有的我要的分页的功能他都已经提供了,但是我在调试的过程中,却怎么也 无法通过,估计是和我的 PDC 版本的原因,这个时候,我就想起了 开心(注:网友名称,他曾经建议我直接安装NGWS beta1 和 Vs7 beta1):)

希望大家如果在 Beta1 上调试成功了以后,一定要告诉豆腐

没有别的办法,我只好就去用我的老办法,用程序去控制,老天,我不想这样,但是我真的没有别的办法了

大家请看程序:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Data.SQL" %>
<HTML><HEAD>
<script runat="server" language="VB">
dim sqlRead as SQLDataReader
dim intStart as integer
dim intLen as integer
dim intPageCount as integer
dim intRecCount as integer
Sub Page_Load(Src As Object, E As EventArgs)
Dim conn As SQLConnection
Dim Cfg as HashTable
Dim sqlcmd As SQLCommand

Cfg = Context.GetConfig("appsettings")
Conn = New SQLConnection(cfg("Conn"))

dim strSQL as string
'实在是没有办法,只好这样来获得 记录总数了
'根据NGWS的帮助上看 似乎有个PagedDataSource 好象功能挺强大
'但是 就是 不知道 应该怎么使用 也没有见过 用他的例子
strSQL="select count(*) as ccount from msgBoard"
sqlcmd = New SQLCommand(strSQL,conn)
sqlcmd.ActiveConnection.Open()
sqlcmd.execute(sqlRead)
sqlRead.Read()
intRecCount=cInt(sqlRead("ccount"))
sqlcmd.ActiveConnection.Close()
strSQL="select * from msgBoard order by msgid desc"
sqlcmd = New SQLCommand(strSQL,conn)
sqlcmd.ActiveConnection.Open()
sqlcmd.execute(sqlRead)


if isNumeric(request.querystring("start")) then
intStart=Cint(request.querystring("start")) '本页数据起使位置
else
intStart=0
end if

intLen=10 '每页需要显示的数据数量
'以下计算 当前的 记录的分页页数
if (intRecCount mod intLen)=0 then
intPageCount=intRecCount/intLen
else
intPageCount=(intRecCount-(intRecCount mod intLen))/intLen+1
end if
dim i as integer
'将得到的sqlRead向后移动 start 指定的 位置
for i=0 to intStart-1
sqlRead.read()
next
end sub
sub WritePage(start as integer,file as string)
'进行分页处理
dim strWrite as string
strWrite="<table border=1 width=100%><tr><td>"
response.write(strWrite)

if start=0 then
strWrite="首页"
else
strWrite="<a href='" & file & "?start=0'>首页</a>"
end if
response.write(strWrite)

if start>=1 then
strWrite="<a href='" & file & "?start=" & cStr(start-intLen) & "'>上页</a>"
else
strWrite="上页"
end if
response.write(strWrite)

if start+intLen<intRecCount then
'还没有到最后一页数据
strWrite="<a href='" & file & "?start=" & cStr(start+intLen) & "'>下页</a>"
else
strWrite="下页"
end if
response.write(strWrite)

if start+intLen<intRecCount then
'还没有到最后一页数据
strWrite="<a href='" & file & "?start=" & cStr((intPageCount-1)*intLen) & "'>末页</a>"
else
strWrite="末页"
end if
response.write(strWrite & "</td><