Paging in ASP.NET Grid View
Let us discuss the Paging in ASSP.NET
Gridview .
This is a beginner tutorial.
For my ease I have bind
Gridview with a List<>
NB: This code is in VB Please use http://www.developerfusion.com/tools/convert/csharp-to-vb/
if u are a c# developer
Public Class Person
Public Sub New(ByVal Name As String, ByVal Age As Integer)
_Name = Name
_Age = Age
End Sub
Private _Age As Integer
Public Property Age() As Integer
Get
Return _Age
End Get
Set(ByVal value As Integer)
_Age = value
End Set
End Property
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
End Class
I wrote a function to bind the
list of class to GridView
Private Sub BindData()
Dim lst As New List(Of Person)()
lst.Add(New Person("Rajesh", 33))
lst.Add(New Person("Aaron", 1))
lst.Add(New Person("Akshatha", 4))
lst.Add(New Person("Joy", 55))
lst.Add(New Person("Sheela", 44))
lst.Add(New Person("Blessy", 21))
GridView1.DataSource = lst
GridView1.DataBind()
End Sub
Till here things are usual. Now
Comes the Paging Concept. To Enable Paging in the
<asp:Gridview/>
<asp:GridView ID="GridView1" runat="server" AllowPaging="true"PageSize="2">
</asp:GridView>
Then in the event
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
BindData()
End Sub
This enables
Paging

There is
again options to have different types of paging
<PagerStyle HorizontalAlign="Center" />
-- Sets the Pager Position
PagerSettings Have Different
Mode
<PagerSettings Mode="NextPreviousFirstLast"FirstPageText="First"PreviousPageText="Previous" NextPageText="Next"LastPageText="Last" />

So that Paging can be made as you
Desire.
Happy Coding