Public Class NeedSex
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("Data") Is Nothing Then
Dim lst As New List(Of Data)
For i As Integer = 0 To 15000
lst.Add(New Data() With {.ID = i, .Name = i.ToString() & "#"})
Next
Session("Data") = lst
End If
If Not IsPostBack Then
PopulateData(1, 30)
End If
End Sub
Private Sub PopulateData(pageIndex As Integer, noOfRecord As Integer)
Dim pageCount As Integer = 0
Dim totalRecord As Integer = 0
Dim lst = DirectCast(Session("Data"), List(Of Data))
Dim data As List(Of Data) = New List(Of Data)
totalRecord = lst.Count
Dim skip As Integer = (pageIndex - 1) * noOfRecord
data = lst.Skip(skip).Take(noOfRecord).ToList()
Dim strText As String = String.Empty
For i As Integer = 0 To data.Count - 1
strText &= data(i).ID & "<br />"
Next
Dim sb1 As New StringBuilder()
Dim sb2 As New StringBuilder()
sb2.Append("$('#dvGrid').html('" & strText & "');")
sb1.Append("$('#dvGrid').empty();")
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "First30Rows", sb1.ToString() & sb2.ToString(), True)
If (totalRecord > 0 AndAlso noOfRecord > 0) Then
pageCount = (totalRecord \ noOfRecord) + If(totalRecord Mod noOfRecord > 0, 1, 0)
hfTotalPage.Value = pageCount.ToString()
End If
End Sub
<System.Web.Services.WebMethod()>
Public Shared Function PopulateDataByJquery(ByVal pageIndex As Integer, ByVal noOfRecord As Integer) As List(Of Data)
Dim lst = DirectCast(HttpContext.Current.Session("Data"), List(Of Data))
Return lst.Skip((pageIndex - 1) * noOfRecord).Take(noOfRecord).ToList()
End Function
<Serializable>
Public Class Data
Public Property ID As Integer
Public Property Name As String
End Class
End Class