温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

VB.NET中怎么实现自动分页

发布时间:2021-07-19 15:56:49 来源:亿速云 阅读:123 作者:Leah 栏目:编程语言

VB.NET中怎么实现自动分页,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

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 窗体设计器生成的代码 "  ''该调用是 Web 窗体设计器所必需的。  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()  End Sub   Private Sub Page_Init(ByVal sender As System.Object,  al e As System.EventArgs) Handles MyBase.Init  ''CODEGEN: 此方法调用是 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  ''长内容分页  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 ''定义每页至少显示字符串数  pagecount = 0 ''获得当前的页数  pa = Request.Params("page")  If (pa = "" Or IsDBNull(pa)) Then  pa = "1" End If  pp = Convert.ToInt32(pa)  ''获得内容  articletxt = contenttext ''判断页面的内容长度是否大于定义的每页至少显示字符串数  If (articletxt.Length >= pagesize) Then '' 如果大于字符串数,则我们可以分页显示  t = articletxt.Length / pagesize ''获得大致的总页数  ''根据目前获得的页数循环  For i = 0 To t  ''如果查询开始位置到查询的范围超出整个内容的长度,那么就不用寻找断点(分页点);反之,查找  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 ''将结果付给要导出的变量  ''Label1.Text = articletext & stat  ''Exit Sub  Else  stops = stat ''分页点的位置也就作为这一页的终点位置  If (start + pagesize >= articletxt.Length) Then ''如果起始位置到查询的范围超出整个内容的长度,  那么这一页的终点位置为内容的终点  stops = articletxt.Length  End If  If (pp = i + 1) Then ''如果是当前,那么输出当前页的内容  articletext = articletxt.Substring(start, stops - start) ''  取内容的起始位置到终点位置这段字符串输出  Label1.Text = articletext End If  start = stat ''将终点位置作为下一页的起始位置  pagecountpagecount = pagecount + 1 ''获得实际页总数  ''Response.Write("-" & pagecount & "-")  End If  Next  End If  ''分页部分(这里就简单多了)  ''定义分页代码变量  If (pagecount > 1) Then ''当页数大于1的时候我们显示页数  ''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

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI