Pagination in GridView

Posted by Johnbhatt under ASP.NET category on | Points: 40 | Views : 1864

Simply we will learn here how to Apply Pagination in ASP.NET GridView Control.

Directly to Code:

In ASPX page, enable paging in GridView.
<asp:GridView ID="gvAllPOD" runat="server" AutoGenerateColumns="false" AlternatingRowStyle-BackColor="LightSeaGreen" HeaderStyle-Font-Bold="true" AllowPaging="true" PageSize="20" onpageindexchanging="gvAllPOD_PageIndexChanging">

In Above Code, we Automatically Generated Columns from DataSource Then AllowPaging = True, so that GridView Data can be Paged, Also We defined PageSize that what amount of Records whould display in Page.

To Apply Pagination, RIght Click in GridView and Choose Properties > Events. Choose PageIndexChanged event and Place Following code in ASPX.CS Page.

protected void gvAllPOD_PageIndexChanging(object sender, GridViewPageEventArgs e)
gvAllPOD.PageIndex = e.NewPageIndex;

Now Check on your Page. What is Happening on Clicking Page Number. You can comment if some queries on above code.

Comments or Responses

Posted by: Sankar20092010 on: 7/27/2012 Level:Starter | Status: [Member] | Points: 10

But here we want to call the database each time we click on page number isn't it ? Is there any other way for not calling again and again.

Thanks and Regards

Posted by: Johnbhatt on: 7/27/2012 Level:Starter | Status: [Member] | Points: 10
Hello Sankar,
First I like to thank you for reading my codes.

As you know, We are binding data on each postback. To prevent this and make this process faster, we use Caching.
If you know about caching, you can bind cached data everytime.

I am slightly busy in this week, Search Sesstion Management in ASP.NET in blog section, I will post a basic and complete post about caching.

Login to post response