大家請看程序: <%@ 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><td>")
strWrite="當前共有留言" & Cstr(intRecCount) & ",現在是第<font color=red>" & cStr((intStart/intLen)+1) & "/" & cstr(intPageCount) & "</font>頁" response.write(strWrite) strWrite="</td></tr></table>" response.write(strWrite) end sub </script> <title>豆腐技術站__aspx分站__查看留言</title> <link rel="stylesheet" type="text/CSS" href="/doufu.css"> </HEAD> <BODY> <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 %> <div align=center> <table border=1 width=80%> <tr> <td width=10%>呢稱</td> <td width=40%><%=sqlRead("nickname")%></td> <td width=10%>IP地址</td> <td width=10%><%=sqlRead("IPAddr")%></td> </tr> <tr> <td width=10%>聯系方式</td> <td width=90% colspan=3><%=sqlRead("email")%></td> </tr> <tr> <td width=10%>留言主題</td> <td width=90% colspan=3><%=sqlRead("msgTitle")%>----<font color=red><%=sqlRead("msgTime")%></font></td> </tr> <tr> <td width=10%>留言內容</td> <td width=90% colspan=3><%=server.HTMLEncode(sqlRead("msgContent"))%></td> </tr> </table> </div> <p></p> <%next%> </body> </html> 終于完了:)
結束語: 在大家看過 三篇文章后,整個的留言版的程序也就已經全部的講完了,客觀的說,通過這個程序我們還無法完全的領略asp+給我們帶來的所有令人興奮的功能,而且還有很多的功能現在似乎還是在宣傳的階段,但是 畢竟現在才是Beta1 的階段,相信在正式版本推出的時候,我們可以看到一個全新的面向 Web 編程的 .net 平臺