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

http://www.asp888.net 豆腐技术站

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

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

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

大家请看程序:

1@ Import Namespace="System.Data" 
1@ Import Namespace="System.Web.Security" 
1@ Import Namespace="System.Web.UI" 
1@ Import Namespace="System.Data.SQL" 
 1<html><head>
 2<script language="VB" runat="server">   
 3dim sqlRead as SQLDataReader   
 4dim intStart as integer   
 5dim intLen as integer   
 6dim intPageCount as integer   
 7dim intRecCount as integer   
 8Sub Page_Load(Src As Object, E As EventArgs)   
 9Dim conn As SQLConnection   
10Dim Cfg as HashTable   
11Dim sqlcmd As SQLCommand 
12
13Cfg = Context.GetConfig("appsettings")   
14Conn = New SQLConnection(cfg("Conn")) 
15
16dim strSQL as string   
17'实在是没有办法,只好这样来获得 记录总数了   
18'根据NGWS的帮助上看 似乎有个PagedDataSource 好象功能挺强大   
19'但是 就是 不知道 应该怎么使用 也没有见过 用他的例子   
20strSQL="select count(*) as ccount from msgBoard"   
21sqlcmd = New SQLCommand(strSQL,conn)   
22sqlcmd.ActiveConnection.Open()   
23sqlcmd.execute(sqlRead)   
24sqlRead.Read()   
25intRecCount=cInt(sqlRead("ccount"))   
26sqlcmd.ActiveConnection.Close()   
27strSQL="select * from msgBoard order by msgid desc"   
28sqlcmd = New SQLCommand(strSQL,conn)   
29sqlcmd.ActiveConnection.Open()   
30sqlcmd.execute(sqlRead) 
31
32  
33if isNumeric(request.querystring("start")) then   
34intStart=Cint(request.querystring("start")) '本页数据起使位置   
35else   
36intStart=0   
37end if 
38
39intLen=10 '每页需要显示的数据数量   
40'以下计算 当前的 记录的分页页数   
41if (intRecCount mod intLen)=0 then   
42intPageCount=intRecCount/intLen   
43else   
44intPageCount=(intRecCount-(intRecCount mod intLen))/intLen+1   
45end if   
46dim i as integer   
47'将得到的sqlRead向后移动 start 指定的 位置   
48for i=0 to intStart-1   
49sqlRead.read()   
50next   
51end sub   
52sub WritePage(start as integer,file as string)   
53'进行分页处理   
54dim strWrite as string   
55strWrite="<table border=1 width=100%><tr><td>"   
56response.write(strWrite) 
57
58if start=0 then   
59strWrite="首页"   
60else   
61strWrite="<a href='" & file & "?start=0'>首页</a>"   
62end if   
63response.write(strWrite) 
64
65if start>=1 then   
66strWrite="<a href='" & file & "?start=" & cStr(start-intLen) & "'>上页</a>"   
67else   
68strWrite="上页"   
69end if   
70response.write(strWrite) 
71
72if start+intLen<intRecCount then   
73'还没有到最后一页数据   
74strWrite="<a href='" & file & "?start=" & cStr(start+intLen) & "'>下页</a>"   
75else   
76strWrite="下页"   
77end if   
78response.write(strWrite) 
79
80if start+intLen<intRecCount then   
81'还没有到最后一页数据   
82strWrite="<a href='" & file & "?start=" & cStr((intPageCount-1)*intLen) & "'>末页</a>"   
83else   
84strWrite="末页"   
85end if   
86response.write(strWrite & "</td><td>") 
87
88strWrite="当前共有留言" & Cstr(intRecCount) & ",现在是第<font color=red>" & cStr((intStart/intLen)+1) & "/" & cstr(intPageCount) & "</font>页"   
89response.write(strWrite)   
90strWrite="</td></tr></table>"   
91response.write(strWrite)   
92end sub   
93</script>
94<title>豆腐技术站__aspx分站__查看留言</title>
95<link href="/doufu.css" rel="stylesheet" type="text/css"/>
96</head>
97<body>
98<a href="http://www.asp888.net">豆腐技术站</a>亲情奉献<br/>   

WritePage(intStart,"a.aspx")
dim atEnd as boolean

for i=0 to intLen-1

atEnd=sqlRead.read()
if not atEnd then exit for

 1<div align="center">
 2<table border="1" width="80%">
 3<tr>
 4<td width="10%">呢称</td>
 5<td width="40%">```
 6=sqlRead("nickname")
 7```</td>
 8<td width="10%">IP地址</td>
 9<td width="10%">```
10=sqlRead("IPAddr")
11```</td>
12</tr>
13<tr>
14<td width="10%">联系方式</td>
15<td colspan="3" width="90%">```
16=sqlRead("email")
17```</td>
18</tr>
19<tr>
20<td width="10%">留言主题</td>
21<td colspan="3" width="90%">```
22=sqlRead("msgTitle")
23```\----<font color="red">```
24=sqlRead("msgTime")
25```</font></td>
26</tr>
27<tr>
28<td width="10%">留言内容</td>
29<td colspan="3" width="90%">```
30=server.HTMLEncode(sqlRead("msgContent"))
31```</td>
32</tr>
33</table>
34</div>
35<p></p>   

next

1</body>
2</html>

终于完了:)

结束语:
在大家看过 三篇文章后,整个的留言版的程序也就已经全部的讲完了,客观的说,通过这个程序
我们还无法完全的领略asp+给我们带来的所有令人兴奋的功能,而且还有很多的功能现在似乎还是在
宣传的阶段,但是 毕竟现在才是Beta1 的阶段,相信在正式版本推出的时候,我们可以看到一个全新
的面向 Web 编程的 .net 平台

Published At
Categories with Web编程
Tagged with
comments powered by Disqus