ASP.Net 2.0 Gridview Paging using C#

by top54u.com 08 Mar, 2008
Spotlight.....

In ASP.Net 2.0 GridView is most often used to display the data retrieved from the database in Tabular form with features of Gridview like data paging, sorting and auto formats.


You can use C# code to bind the SQL data with GridView control and follow the following simple steps to make your ASP.Net GridView control with paging enabled.

 

First of all drag the GridView control from Data controls menu.

 

<asp:GridView id="GridView1" runat="server"></asp:GridView>

 

It will add the GridView control HTML source code as given above. Now click on GridView control to load the control properties at right side panel.

 

 

To enable the paging in GridView control select True from the dropdown list of AllowPaging property of GridView control as shown in the above image.

 

It will add AllowPaging="True" in HTML source code of Gridview.

 

Next step is to bind the data with Gridview control and handle the GridView paging event.

 

 

To bind the PageIndexChanging of GridView control, double click on the PageIndexChanging event in the properties of Gridview. It will add the event in HTML source code as well as C# code.

 

HTML source code for GridView Control:

 

<asp:GridView id="GridView1" runat="server" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="5"></asp:GridView>


 
You can set the PageSize value as per your requirement.

 

C# Code Sample:

 

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        bindGridView();
    }

 

After data binding with GridView control you will get the results as shown in the above image of Gridview control on page load.

Download the free complete source code in ASP.Net 2.0 C# code for Gridview paging:

gridview paging.zip (2.54 kb)

gridview paging.rar (2.45 kb)

Also Learn

ASP.Net 2.0 Gridview Sorting Using C#

Spotlight.....

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , , , , , , ,

Comments

3/26/2008 10:45:40 PM

suresh

This very useful for me

suresh in

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/23/2008 9:02:34 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....