.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Basic Paging in ASP.NET GridView

Posted By:Baimey Rajesh       Posted Date: August 13, 2012    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

Gridview provides an easy way to anable paging for the huge records. We'll discuss on the different modes as well

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
            Return _Age
        End Get
        Set(ByVal value As Integer)
            _Age = value
        End Set
    End Property

    Private _Name As String

    Public Property Name() As String
            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
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">

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
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

 Subscribe to Articles


Further Readings:

Author: netgrid         Company URL: http://www.dotnetspark.com
Posted Date: September 18, 2012

thank you...I tried with this coding . I have used a single gridview for viewing details date wise(using calendar) and also for viewing fully.

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend