顯示當前頁的留言信息:
使用一個asp:repeater控件顯示信息,我沒有使用dataset 的分頁是因為那樣很浪費資源,每次把全部數(shù)據(jù)都讀取的說,我是只讀當page頁面數(shù)據(jù)的:index.aspx
dim PAGENO as integer dim pagestr as string = request.QueryString("page") if not IsNumeric(pagestr) then PAGENO = 1 else PAGENO = int32.parse(Microsoft.VisualBasic.Left(pagestr, 10)) end if dim PAGELIST AS integer = 6 '每頁的信息條數(shù)
為了防止page參數(shù)的非法性,我們做了一點額外的工作:轉(zhuǎn)換類型到int32合法。
然后讀取當頁信息:
rpt_postlist.datasource = CoutData.CoutGuestData(PAGENO,PAGELIST ) '這里返回了dataset對象 rpt_postlist.databind()
其中CoutData::CoutGuestData也是共享方法:
'返回計數(shù), shared Function CoutGuestData (pagei as integer,optional PAGESIZE as integer = 6 ) as DataSet dim PAGENO as integer = pagei dim STARTNO as integer = PAGESIZE *( PAGENO-1 ) '得到開始的記錄 dim SQLSTR as string
SQLSTR = "select top "& PAGESIZE &" [book_id],[user_name],[book_title], [book_contents],[book_type],[book_time] from [szd_book] " if PAGENO <> 1 then SQLSTR &= "where [book_id] not in( select top "& STARTNO &" [book_id] from [szd_book] order by [book_id] desc) " end if SQLSTR &= " order by [book_id] desc" Dim conn as New conn() return conn.GetDataSet(SQLSTR) End Function
shared Function CoutBbcode (ByRef strs as string ,Optional htmlorubb as integer = 0 ) as string if htmlorubb = 0 then return CjjerBase.bbCode.GetBbcode(strs) else return strs End if End Function
這個方法比較簡單,思路就是根據(jù)當前頁計算記錄的開始條 + 每頁數(shù),出現(xiàn)意外及時變換sql,然后讀取數(shù)據(jù)庫,返回dataset。
圖示:
顯示當前的分頁信息:
pageinfo.text = CoutData.CoutPageLabel( PAGENO ,PAGELIST)
CoutData::CoutPageLabel
Shared Function CoutPageLabel( pagenoi as integer ,optional PAGESIZE as integer = 6 ) as string dim PAGENO as integer dim pagestr as string = pagenoi PAGENO = int32.parse(Microsoft.VisualBasic.Left(pagestr, 10)) dim ALLNO as integer dim RECORDSESQL as string = " select count([book_id]) from [szd_book]" Dim conn as New conn() ALLNO = conn.ExecuteScalar(RECORDSESQL) conn.close() dim STARTNO as integer = PAGESIZE *( PAGENO-1 ) '得到開始的記錄 dim COUNTPAGE AS integer = CInt ( ALLNO / PAGESIZE + 0.5 ) '得到總頁數(shù) if ( ALLNO mod PAGESIZE ) = 0 then COUNTPAGE -= 1 dim PAGESTRS AS string if PAGENO > COUNTPAGE then PAGENO = COUNTPAGE PAGESTRS = "總數(shù):" & ALLNO & "頁數(shù):" & COUNTPAGE & ",當前第" & PAGENO & "頁," dim pageI as integer for pageI = 1 to COUNTPAGE if pageI = PAGENO PAGESTRS &= pageI else PAGESTRS &= "<a href=""index.aspx?page=" & pageI & """> " & pageI & " </a>" end if next return PAGESTRS End Function
思路就是:先獲取總數(shù),規(guī)劃根據(jù)總數(shù)和每頁的信息數(shù)目for循環(huán)即可。
圖示:
出處:藍色理想
責(zé)任編輯:moby
上一頁 用戶控件設(shè)計 下一頁
◎進入論壇網(wǎng)絡(luò)編程版塊參加討論
|