What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 12287 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > Pagination in GridView ...
Johnbhatt

Pagination in GridView

 Code Snippet posted by: Johnbhatt | Posted on: 6/27/2012 | Category: ASP.NET Codes | Views: 858 | Status: [Member] | Points: 40 | Alert Moderator   


Hi,

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;
BindGVAllPOD();
}

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

John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com
Found interesting? Add this to:


 Responses

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

Hi....

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

Sankar

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

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.

John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com

>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 5:05:49 PM