VB.net程序实现分页

 1       Private Function PageCalc(ByVal TotalIDs As String, ByVal PageNumber As Integer, ByVal PerPage As Integer, ByRef TotalAmount As Integer, ByRef TotalPage As Integer) As String
 2         On Error Resume Next
 3 
 4         'Split to arr
 5         Dim IDsArr() As String = TotalIDs.Split(",")
 6 
 7         'Calc TotalAmount and TotalPage
 8         TotalAmount = IDsArr.Length
 9         TotalPage = Int(TotalAmount * 1.0 / PerPage)
10         If TotalAmount Mod PerPage > 0 Then
11             TotalPage += 1
12         End If
13 
14         'ReCalc PageNumber
15         If PageNumber < 1 Then
16             PageNumber = 1
17         End If
18         If PageNumber > TotalPage Then
19             PageNumber = TotalPage
20         End If
21 
22         'StartPos and EndPos
23         Dim StartPos As Integer = 0
24         Dim EndPos As Integer = 0
25         StartPos = (PageNumber - 1) * PerPage
26         EndPos = PageNumber * PerPage - 1
27         If EndPos > TotalAmount - 1 Then
28             EndPos = TotalAmount - 1
29         End If
30 
31         'Get ResultIDs
32         Dim ResultIDs As String = ""
33         For I As Integer = StartPos To EndPos
34             ResultIDs = ResultIDs & "," & IDsArr(I)
35         Next
36         If ResultIDs <> "" Then
37             ResultIDs = ResultIDs.Trim(",")
38         End If
39 
40         'Return
41         Return ResultIDs
42       End Function
View Code
原文地址:https://www.cnblogs.com/pyblogs/p/3501965.html