国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

VB.Net 開發(fā)的長內(nèi)容自動分頁功能

2024-07-10 13:05:37
字體:
供稿:網(wǎng)友
國內(nèi)最大的酷站演示中心!
長內(nèi)容即可以手動分頁也可以自動分頁。
采用自動分頁功能,只需告訴計算機每頁大約字數(shù)就可以了。
下面附源碼,方便自己,也方便大家研究:

public class webform1
inherits system.web.ui.page
protected withevents label1 as system.web.ui.webcontrols.label
protected withevents label2 as system.web.ui.webcontrols.label
protected withevents label3 as system.web.ui.webcontrols.label
protected withevents label4 as system.web.ui.webcontrols.label

#region " web 窗體設計器生成的代碼 "

'該調(diào)用是 web 窗體設計器所必需的。
<system.diagnostics.debuggerstepthrough()> private sub initializecomponent()

end sub

private sub page_init(byval sender as system.object, byval e as system.eventargs) handles mybase.init
'codegen: 此方法調(diào)用是 web 窗體設計器所必需的
'不要使用代碼編輯器修改它。
initializecomponent()
end sub

#end region

private sub page_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
'在此處放置初始化頁的用戶代碼
pages()
end sub

'長內(nèi)容分頁
sub pages()
dim i, start, stops, t, stat, statt, pp, pagecount, pagesize, articleid as integer
dim pa, articletxt, articletext, contenttext, html as string
contenttext = "<p>aaaaaaa</p><p>bbbbbbbbbbbb</p><p>cccccccccccccccc</p>"
'變量初始值
stat = 0
statt = 0
start = 0 '開始查詢的字符串位置,初始為0
stops = 0
pagesize = 2 '定義每頁至少顯示字符串數(shù)
pagecount = 0

'獲得當前的頁數(shù)
pa = request.params("page")
if (pa = "" or isdbnull(pa)) then
pa = "1"
end if
pp = convert.toint32(pa)

'獲得內(nèi)容
articletxt = contenttext

'判斷頁面的內(nèi)容長度是否大于定義的每頁至少顯示字符串數(shù)
if (articletxt.length >= pagesize) then ' 如果大于字符串數(shù),則我們可以分頁顯示
t = articletxt.length / pagesize '獲得大致的總頁數(shù)
'根據(jù)目前獲得的頁數(shù)循環(huán)
for i = 0 to t
'如果查詢開始位置到查詢的范圍超出整個內(nèi)容的長度,那么就不用尋找斷點(分頁點);反之,查找
if (start + pagesize < articletxt.length) then
stat = articletxt.indexof("</p>", start + pagesize) '查找</p>分頁點的位置
'如果找不到
'if (stat <= 0) then
'stat = articletxt.indexof("</p>", start + pagesize) '查找</p>分頁點的位置;這里您可以自己設置分頁點的判斷
'end if
end if
'response.write("'" & stat & "'")
if (stat <= 0) then
'如果找不到分頁點,說明不能分頁,也就不需要做其他的勞動了;否則,就進行分頁
'articletext = articletxt '將結(jié)果付給要導出的變量
'label1.text = articletext & stat
'exit sub
else

stops = stat '分頁點的位置也就作為這一頁的終點位置
if (start + pagesize >= articletxt.length) then '如果起始位置到查詢的范圍超出整個內(nèi)容的長度,那么這一頁的終點位置為內(nèi)容的終點
stops = articletxt.length
end if
if (pp = i + 1) then '如果是當前,那么輸出當前頁的內(nèi)容
articletext = articletxt.substring(start, stops - start) '取內(nèi)容的起始位置到終點位置這段字符串輸出
label1.text = articletext
end if
start = stat '將終點位置作為下一頁的起始位置
pagecount = pagecount + 1 '獲得實際頁總數(shù)
'response.write("-" & pagecount & "-")
end if
next
end if
'分頁部分(這里就簡單多了)
'定義分頁代碼變量

if (pagecount > 1) then '當頁數(shù)大于1的時候我們顯示頁數(shù)
'response.write(pp)
if (pp - 1 > 0) then '顯示上一頁,方便瀏覽
html += "<a href=?id=" & articleid & "&page=" & (pp - 1) & ">[上一頁]</a> "
else
if pp = 1 then
html += "[<font color=#cccccc>上一頁</font>] "
else
html += "<a href=?id=" & articleid & "&page=" & (1) & ">[上一頁]</a> "
end if

end if
for i = 1 to pagecount

if (i = pp) then '如果是當前頁,加粗顯示
html += "<b>[" & i & "]</b> "
else
html += "<a href=?id=" & articleid & "&page=" & i & ">[" & i & "]</a> "
end if
next
if (pp + 1 > pagecount) then '顯示下一頁,方便瀏覽
if pp = pagecount then
html += "[<font color=#cccccc>下一頁</font>] "
else
html += "<a href=?id=" & articleid & "&page=" & (pagecount) & ">[下一頁]</a></p>"
end if
else
html += "<a href=?id=" & articleid & "&page=" & (pp + 1) & ">[下一頁]</a></p>"
end if
end if
label2.text = html
end sub

end class

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 聂拉木县| 九台市| 潜山县| 航空| 建宁县| 涟水县| 夏津县| 道孚县| 嘉禾县| 隆尧县| 德惠市| 商城县| 环江| 扶余县| 大姚县| 汉中市| 陆丰市| 赣榆县| 灵璧县| 江阴市| 祁阳县| 隆化县| 忻城县| 珲春市| 徐汇区| 波密县| 饶平县| 昭通市| 武陟县| 扎赉特旗| 连平县| 万安县| 东乌珠穆沁旗| 湖南省| 龙门县| 湾仔区| 商都县| 临武县| 安乡县| 新化县| 阳西县|