How to Implement Asp.Net GridView Pagination Using C#.Net & VB.Net

In this article i am going to explain about How to Implement Asp.Net   GridView Pagination Using C#.Net & VB.Net. This is achieved by using the AllowPaging,PageSize and OnPageIndexChanging properties of the GridView.

In my previous article i have explained about Convert Dataset Datatable To Json Data Array In Asp.Net C#.Net & VB.Net Or How To Use JavaScriptSerializer To Convert Datatable To Json Data Array ,How To Show Tooltip On Mouse Hover In Gridview In Using JQuery In ASP.Net C#.Net & VB.Net,SQL Script To Drop Multiple Tables,Procedures At Once ,SQL Script To Drop Multiple Tables,Procedures At Once ,Convert Dataset Datatable To Json Data Array,SQL Script To Drop Multiple Tables,Procedures At Once In Sql Server,Highlight,Change Color Of Row On Mouseover In Grid View Using CSS – C#.Net ASP.Net VB.Net,Programmatically Group Gridview Column Headers and many articles in C#.Net,ASP.Net,VB.Net,Grid View,Javascript,jQuery,SQL Server and many other topics.

For explanation purpose i have created a table called UserDetails in my local database and inserted some sample records. And also i have created a procedure called GetUsersDetails which will return all the users detail from the users table. below is the sql script used.

Now open the visual studio and create a new website. In the default.aspx file drag and drop the gridview control from the toolbox and set the AllowPaging,PageSize and OnPageIndexChanging properties like below mentioned html markup.

HTML MarkUp:

Asp.Net Gridview Pagination using
C#.Net & VB.Net by .NetPickles

Now in the web.config file include the connection string information.

Web.Config:

Now please import the below mentioned namespaces in your code behind file to make use of it.

C#.Net:

VB.Net:

After that in the code behind file i have written the code to fetch the data from the database and bind it to the gridview. And also i have written the code for gridview pagination. Below is the code i wrote.

C#.Net:

VB.Net:

Now if you run the code then you can see the page numbers below your grid. This page numbers are generated based on the total no of records and page size mentioned in the gridview.

The output will look like below.

Output of How to Implement Asp.Net GridView Pagination Using C#.Net & VB.Net

Download SourceCode:

Sourcecode of How to Implement Asp.Net GridView Pagination Using C#.Net & VB.Net

You May Also Like…

Do you like this post. Please share with your friends. Happy coding…

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!