It is a control used to move to any pages that we need .We can set the page size of the grid using this control. We can sort any column in ascending and descending order by just clicking corresponding heading with this control. Using this control users can move to the first and last page with just a button click. It also displays the total records and total number of pages available with respect to the given page size.
Pagination & Sorting in User control
It
is a control used to move to any pages that we need .We can set the
page size of the grid using this control. We can sort any column in
ascending and descending order by just clicking corresponding heading
with this control. Using this control users can move to the first and
last page with just a button click. It also displays the total
records and total number of pages available with respect to the given
page size.

Features
Immediate
page navigation
If
we change the value in the text box within the limit of the pages
available it will call the event defined in code behind of aspx
page for user control . Event in the code behind of aspx page will
call the stored procedure to bind the listview.
Define
Records count / page
If
we change the drop down value then it will call the event defined in
code behind of aspx
page for user control . Event in the code behind of aspx page
will call the stored procedure to bind the list view.
Sort
ascending or descending based on any of the field in list view by
just clicking on heading.
On
clicking the heading the method defined in user control will be
called ,and it will hide other images in the list view header and ,
call back the aspx page method with current column name and order
as parameter . Method in the aspx page will
call the stored procedure to bind the list view and make the
corresponding image visible.
-
Navigate
to last and first page with a button click.
With
the click of the First Page it will send the page number as 1 .It
will set the value of text box as the same. It
will call the event defined in the code behind page of aspx page
for user control . Event in the code behind of aspx page will call
the stored procedure to bind the list view. With the click of the
Last Page it will sent the page number as the maximum number of
pages available. It
will set the value of text box as the same. It
will call the event defined in code behind of aspx page for user
control. Event in the code behind of aspx page will call the stored
procedure to bind the list view.
Displays
the total records
When
the page loads the user control will bind the value of the total
records from the database by calling the method
defined in aspx page with the page number specified in the text box
as parameter from the user control . Method in the aspx page will
call the stored procedure to bind the list view.

Stored Procedure
Create a Stored Procedure for each page
for Selecting the needed columns in the List View with the parameters
page number,page size, column name & order to which we need to
apply sorting and the order in which we need to get it sorted
(ascending or descending).
User Control
Make the above
table as user control design. Define the functions and events.
Inherit the interface that we created in Abstract class. To call the
function from the user control we must use the following code in code
behind of user control.

// write code here
AbstractClass page=(AbstractClass)Page;
page.ListGridview(CurrentPage,PageSize,SortOrder);
Design Page
Register the user
control in the top of the aspx page where we add pagination.
// write code here
<%@ Register src="~/Paging.ascx" TagName="page" TagPrefix="uc1"%>
Now
place the user control in the place we need it
<uc1:page ID="pageGrid" runat="server" Visible="true"/>
For
each heading in the Grid we should add a link button. It should
contain a Command Name which gives the id of the image next to it and Command Argument which contains the Column Name in the database. An
image should be added to show whether it is in ascending order or
descending order.<asp:LinkButton ID="lnkCode" ToolTip="Click to sort" CssClass="lnkFont" CommandName="btnSortCode" CommandArgument="Code" runat="server">Route Code</asp:LinkButton>
<img src="~/Images/Down_Arrow.jpg" id="btnSortCode" runat="server" />
Code
Behind
Method
to bind grid should be over ridden from code behind. Call List View's Item Command event for sorting .
protected void lvRoute_ItemCommand(object sender,ListViewCommandEventArgs e)
{}
Inside
this event we can call the functions that we declare in User Control.
For that we should give usercontrolId.HideArrows() and
usercontrolId.SortRecords().For Paging we should call the user
control event Pager_Changed which is defined in User control.
protected void Pager_Changed(object sender,PagerEventArgs e)
{
var pageNumber=e.PageNumber;
var pageSize=e.PageSize;
ListGridview(pageNumber,pageSize,hdnSortOrder.Value);
}
Abstract Class
Create an abstract
class in the App Code to create an abstract method to call this
method from user control & to give the defenition of the same
from the aspx.cs page. Create an interface to define two methods one
to hide arrows in the grid and other to get the sort order of the
grid.
public interface IMethods
{
void SortRecords(string buttonName,string ColumnName,HtmlImage lnkSortCode);
void HideSortIcons(string buttonName,string UniqueID);
}
public abstract class AbstractClass:System.Web.UI.Page
{
public AbstractClass()
{
}
public abstract string ListGridView(int CurrentPage,int PagingSize,string SortOrder);
}