新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
淺析VB.NET開發(fā)自動分頁
VB.NET還是比較常用的,于是我研究了一下VB.NET開發(fā)自動分頁,在這里拿出來和大家分享一下,希望對大家有用。

成都創(chuàng)新互聯(lián)公司成都網(wǎng)站建設(shè)按需網(wǎng)站制作,是成都網(wǎng)站開發(fā)公司,為石牌坊提供網(wǎng)站建設(shè)服務(wù),有成熟的網(wǎng)站定制合作流程,提供網(wǎng)站定制設(shè)計(jì)服務(wù):原型圖制作、網(wǎng)站創(chuàng)意設(shè)計(jì)、前端HTML5制作、后臺程序開發(fā)等。成都網(wǎng)站制作熱線:13518219792
長內(nèi)容即可以手動分頁也可以自動分頁。采用自動分頁功能,只需告訴計(jì)算機(jī)每頁大約字?jǐn)?shù)就可以了。以下是介紹VB.NET開發(fā)自動分頁
下面附源碼,方便自己,也方便大家:
- 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 窗體設(shè)計(jì)器生成的代碼 "
- ''該調(diào)用是 Web 窗體設(shè)計(jì)器所必需的。
()> Private Sub InitializeComponent() - End Sub
- Private Sub Page_Init(ByVal sender As System.Object,
- al e As System.EventArgs) Handles MyBase.Init
- ''CODEGEN: 此方法調(diào)用是 Web 窗體設(shè)計(jì)器所必需的
- ''不要使用代碼編輯器修改它。
- 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 = "
aaaaaaa
bbbbbbbbbbbb
cccccccccccccccc
"- ''變量初始值
- stat = 0
- statt = 0
- start = 0 ''開始查詢的字符串位置,初始為0
- stops = 0
- pagesize = 2 ''定義每頁至少顯示字符串?dāng)?shù)
- pagecount = 0
- ''獲得當(dāng)前的頁數(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)容長度是否大于定義的每頁至少顯示字符串?dāng)?shù)
- If (articletxt.Length >= pagesize) Then '' 如果大于字符串?dāng)?shù),則我們可以分頁顯示
- t = articletxt.Length / pagesize ''獲得大致的總頁數(shù)
- ''根據(jù)目前獲得的頁數(shù)循環(huán)
- For i = 0 To t
- ''如果查詢開始位置到查詢的范圍超出整個內(nèi)容的長度,那么就不用尋找斷點(diǎn)(分頁點(diǎn));反之,查找
- If (start + pagesize < articletxt.Length) Then
- stat = articletxt.IndexOf("", start + pagesize) ''查找分頁點(diǎn)的位置
- ''如果找不到
- ''If (stat <= 0) Then
- ''stat = articletxt.IndexOf("", start + pagesize) ''查找分頁點(diǎn)的位置;
- 這里您可以自己設(shè)置分頁點(diǎn)的判斷
- ''End If
- End If
- ''Response.Write("''" & stat & "''")
- If (stat <= 0) Then
- ''如果找不到分頁點(diǎn),說明不能分頁,也就不需要做其他的勞動了;否則,就進(jìn)行分頁
- ''articletext = articletxt ''將結(jié)果付給要導(dǎo)出的變量
- ''Label1.Text = articletext & stat
- ''Exit Sub
- Else
- stops = stat ''分頁點(diǎn)的位置也就作為這一頁的終點(diǎn)位置
- If (start + pagesize >= articletxt.Length) Then ''如果起始位置到查詢的范圍超出整個內(nèi)容的長度,
- 那么這一頁的終點(diǎn)位置為內(nèi)容的終點(diǎn)
- stops = articletxt.Length
- End If
- If (pp = i + 1) Then ''如果是當(dāng)前,那么輸出當(dāng)前頁的內(nèi)容
- articletext = articletxt.Substring(start, stops - start) ''
- 取內(nèi)容的起始位置到終點(diǎn)位置這段字符串輸出
- Label1.Text = articletext
- End If
- start = stat ''將終點(diǎn)位置作為下一頁的起始位置
- pagecountpagecount = pagecount + 1 ''獲得實(shí)際頁總數(shù)
- ''Response.Write("-" & pagecount & "-")
- End If
- Next
- End If
- ''分頁部分(這里就簡單多了)
- ''定義分頁代碼變量
- If (pagecount > 1) Then ''當(dāng)頁數(shù)大于1的時(shí)候我們顯示頁數(shù)
- ''Response.Write(pp)
- If (pp - 1 > 0) Then ''顯示上一頁,方便瀏覽
- html += " href=?id=" & articleid & "&page=" & (pp - 1) & ">[上一頁] "
- Else
- If pp = 1 Then
- html += "[ color=#cccccc>上一頁] "
- Else
- html += " href=?id=" & articleid & "&page=" & (1) & ">[上一頁] "
- End If
- End If
- For i = 1 To pagecount
- If (i = pp) Then ''如果是當(dāng)前頁,加粗顯示
- html += "[" & i & "] "
- Else
- html += " href=?id=" & articleid & "&page=" & i & ">[" & i & "] "
- End If
- Next
- If (pp + 1 > pagecount) Then ''顯示下一頁,方便瀏覽
- If pp = pagecount Then
- html += "[ color=#cccccc>下一頁] "
- Else
- html += " href=?id=" & articleid & "&page=" & (pagecount) & ">[下一頁]"
- End If
- Else
- html += " href=?id=" & articleid & "&page=" & (pp + 1) & ">[下一頁]"
- End If
- End If
- Label2.Text = html
- End Sub
- End Class
網(wǎng)站欄目:淺析VB.NET開發(fā)自動分頁
網(wǎng)頁路徑:http://m.fisionsoft.com.cn/article/djooeec.html


咨詢
建站咨詢
