vb.net development of long content automatic paging function

Source: Internet
Author: User
Page-length content can be manually paginated or automatically paged.
With automatic paging function, just tell the computer about the number of words per page can be.
The following source code, convenient for their own, but also convenient for everyone to study:

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 the code generated by the Web Forms Designer

' This call is required by the Web Forms Designer.
<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: This method call is required by the Web Forms Designer
' Do not modify it using the Code Editor.
InitializeComponent ()
End Sub

#End Region

Private Sub Page_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load
' The user code to place the initialization page here
Pages ()
End Sub

' Long content paging
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>"
' Variable initial value
Stat = 0
Statt = 0
Start = 0 ' string position of the start query, initially 0
Stops = 0
pagesize = 2 ' defines at least the number of strings displayed per page
PageCount = 0

' Get the current number of pages
PA = request.params ("page")
If (PA = "" Or IsDBNull (PA)) Then
PA = "1"
End If
pp = Convert.ToInt32 (PA)

' Get content
Articletxt = ContentText

' Determines whether the content length of a page is greater than the number of characters per page defined
If (Articletxt. Length >= pagesize) Then ' if it is greater than the number of strings, then we can page-display
t = articletxt. Length/pagesize ' Get roughly the total number of pages
' Based on the current number of page loops
For i = 0 to T
' If the query starts at a range beyond the length of the entire content, you don't have to look for breakpoints (page points);
If (start + pagesize < Articletxt. Length) Then
Stat = Articletxt. IndexOf ("</p>", start + pagesize) ' Find </P> location of page points
' If you can't find the
' If (stat <= 0) Then
' stat = articletxt. IndexOf ("</p>", start + pagesize) ' Find </p> the location of the paging point; Here you can set your own page-point judgment
' End If
End If
' Response.Write ("" & Stat & "")
IF (stat <= 0) Then
' If you can't find the paging point, you can't page, you don't need to do other work;
' ArticleText = Articletxt ' will pay the result to the variable to be exported
' Label1.Text = articletext & Stat
' Exit Sub
Else

Stops = Stat ' The location of the paging point as the end point of the page
If (start + pagesize >= articletxt). Length) Then ' If the range of the start to the query exceeds the length of the entire content, then the end of the page is the end of the content
Stops = Articletxt. Length
End If
if (pp = i + 1) Then ' If it is current, then output the contents of the current page
ArticleText = Articletxt. Substring (Start, Stops-start) ' fetch the starting position of the content to the end position this string output
Label1.Text = ArticleText
End If
Start = Stat ' places the end position as the starting position for the next page
PageCount = PageCount + 1 ' Get the total number of actual pages
' Response.Write ("-" & PageCount & "-")
End If
Next
End If
' Pagination section (it's much simpler here.)
' Define the paging code variable

if (PageCount > 1) Then ' when the page is greater than 1 we show the number of pages
' Response.Write (PP)
If (pp-1 > 0) Then ' Show previous page for easy browsing
html = "<a href=?id=" & ArticleID & "&page=" & (pp-1) & ">[prev]</a>"
Else
If pp = 1 Then
html = "[<font color= #cccccc > Prev </font>]"
Else
HTML + "<a href=?id=" & ArticleID & "&page=" & (1) & ">[prev]</a>"
End If

End If
For i = 1 to PageCount

if (i = PP) Then ' If it is the current page, bold display
HTML + + "<b>[" & I & "]</b>"
Else
HTML + "<a href=?id=" & ArticleID & "&page=" & I & ">[" & I & "]</a>"
End If
Next
If (pp + 1 > PageCount) Then ' show next page for easy browsing
If pp = PageCount Then
html = "[<font color= #cccccc > Next </font>]"
Else
html = "<a href=?id=" & ArticleID & "&page=" & (PageCount) & ">[next page]</a></p>"
End If
Else
HTML + + "<a href=?id=" & ArticleID & "&page=" & (pp + 1) & ">[next page]</a></p>"
End If
End If
Label2.Text = html
End Sub

End Class



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.