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


Top 5 Contributors of the Month
satyapriyanayak
Jean Paul
SP
Sambanthamoorthy
Swati Kadam

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://baimey.wordpress.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
        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

 Subscribe to Articles

     

Further Readings:

Responses
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.
http://www.dapfor.com/en/net-suite/net-grid/tutorial/data-grouping


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