Fork me on GitHub

AspNetPager Class

Custom paging control for ASP.NET web form application.

C# Syntax:

public class AspNetPager:WebControl, INamingContainer, IPostBackEventHandler, IPostBackDataHandler

Properties:

NameDescription
AlwaysShow Gets or sets a value indicating whether AspNetPager is always shown even there's only one page of data. The default value is false.
AlwaysShowFirstLastPageNumber Gets or sets a value indicating whether the first and last numeric paging buttons are always shown.
ButtonImageAlign Gets or sets the horizontal alignment of the image buttons.
ButtonImageExtension Gets or sets the image file extension of paging buttons, such as "gif" or "jpg".
ButtonImageNameExtension Gets or sets the image file name extension of paging buttons.
CloneFrom Gets or sets the AspNetPager control id that need to be cloned to the current AspNetPager.
CpiButtonImageNameExtension Gets or sets the image file name extension of the current page paging button.
CssClass Gets or sets the Cascading Style Sheet (CSS) class rendered by the AspNetPager control on the client.
CurrentPageButtonClass Gets or sets the css class name to be applied to the current page paging button.
CurrentPageButtonPosition Gets or sets the position of the current page paging button.
CurrentPageButtonStyle Gets or sets the css styles to be applied to the current page paging button.
CurrentPageButtonTextFormatString Gets or sets the text formatting to be applied to the current page paging button.
CurrentPageIndex Gets or sets the current page index.
CustomInfoClass Gets or sets the css class name to be applied to the custom info region.
CustomInfoHTML Gets or sets the HTML to be displayed in the custom info region.
CustomInfoSectionWidth Gets or sets the width of the custom info region.
CustomInfoStyle Gets or sets the css styles to be applied to the custom info region.
CustomInfoTextAlign Gets or sets how text is aligned in the custom info region.
DisabledButtonImageNameExtension Gets or sets the image file name extension of the disabled paging buttons.
EnableTheming Gets or sets a value indicating whether themes apply to the AspNetPager control.
EnableUrlRewriting Gets or sets a value indicating whether url rewriting is enabled.
EndRecordIndex Gets the index of the last record that is displayed on a page of data.
FirstPageText Gets or sets the text to display for the first-page button.
FirstPageUrlRewritePattern Gets or sets the url rewrite pattern for the url of the first page when in url paging mode.
ImagePath Gets or sets the image path when paging button type is set to image.
InvalidPageIndexErrorMessage Gets or sets the error message displayed to the client when user entered page index is not valid.
LastPageText Gets or sets the text to display for the last-page button.
LayoutType Gets or sets the layout type of the AspNetPager control.
MoreButtonType Gets or sets the type of the more... paging buttons.
NavigationButtonsPosition Gets or sets the position of the First,Prev,Next and Last navigation paging buttons.
NavigationButtonType Gets or sets the type of navigation buttons(first/last/prev/next).
NavigationToolTipTextFormatString Gets or sets the formatting to be applied to the navigation tooltip, for example "go to page {0}".
NextPageText Gets or sets the text to display for the next-page button.
NumericButtonCount Gets or sets the number of numeric page buttons to display in the AspNetPager.
NumericButtonTextFormatString Gets or sets the text formatting to be applied to the numeric paging buttons, for example "[{0}]" or "-{0}-".
NumericButtonType Gets or sets the type of the numeric paging buttons.
PageCount Gets the total page count.
PageIndexBoxClass Gets or sets the css class name to be applied to the page index box.
PageIndexBoxStyle Gets or sets the css styles to be applied to the page index box.
PageIndexBoxType Gets or sets the type of page index box.
PageIndexOutOfRangeErrorMessage Gets or sets the error message displayed to the client when user entered page index is out of range.
PageSize Gets or sets the number of records to display on a page.
PagesRemain Gets the remaining page numbers after current page.
PagingButtonLayoutType Gets or sets the layout type of all paging buttons.
PagingButtonSpacing Gets or sets the amount of horizontal spacing between paging buttons.
PagingButtonType Gets or sets the type of numeric paging buttons, can be either text or image, default value is text.
PrevPageText Gets or sets the text to display for the prev-page button.
RecordCount Gets or sets the total records count to be paged.
RecordsRemain Gets or sets the total remaining records after current page.
ReverseUrlPageIndex Gets or sets a value indicating whether url page index is reversed when in url paging mode.
ShowBoxThreshold Gets or sets the maxinum page number threashold to display page index box.
ShowCustomInfoSection Gets or sets the display mode of the custom info section.
ShowDisabledButtons Gets or sets a value indicating whether disabled buttons are displayed.
ShowFirstLast Gets or sets a value indicating whether the first and last paging buttons are displayed.
ShowMoreButtons Gets or sets a value indicating whether the more... paging buttons are displayed.
ShowNavigationToolTip Gets or sets a value indicating whether tooltips are shown when the mouse moves over paging elements.
ShowPageIndex Gets or sets a value indicating whether the page index box is displayed.
ShowPageIndexBox Gets or sets the display mode for the page index box.
ShowPrevNext Gets or sets a value indicating whether the prev and next paging buttons are displayed.
SkinID Gets or sets the skin to apply to the control.
StartRecordIndex Gets the index of the first record that is displayed on a page of data.
SubmitButtonClass Gets or sets the css class name to be applied to the submit button.
SubmitButtonImageUrl Gets or sets the url of the submit button image. The default is null.
SubmitButtonStyle Gets or sets the css styles to be applied to the submit button.
SubmitButtonText Gets or sets the text displayed on the submit button.
TextAfterPageIndexBox Gets or sets the text after page index box.
TextBeforePageIndexBox Gets or sets the text before page index box.
UrlPageIndexName Gets or sets the url parameter name for the page index when in url paging mode. Default value is "page".
UrlPageSizeName Gets or sets the page size parameter name in url. If the value of this property is not null and great than 0, then the PageSize property will use this value as the default value.
UrlPaging Gets or sets a value indicating whether url paging is enabled.
UrlPagingTarget Gets or sets the name of the target window or frame that the page should open in.
UrlRewritePattern Gets or sets the url rewrite pattern for paging urls generation when in url paging mode.
Wrap Gets or sets a value indicating whether the content wraps within the AspNetPager.

Methods:

NameDescription
OnInit Overwrite the System.Web.UI.Control.OnInit method.
OnLoad Overwrite the System.Web.UI.Control.OnLoad method.
OnPreRender overwrite the System.Web.UI.Control.OnPreRender method.
AddAttributesToRender Overwrite the System.Web.UI.WebControls.WebControl.AddAttributesToRender method
RenderBeginTag Overwrite the System.Web.UI.WebControls.WebControl.RenderBeginTag method.
RenderEndTag Overwrite the System.Web.UI.WebControls.WebControl.RenderEndTag method.
RenderContents Overwrite the System.Web.UI.WebControls.WebControl.RenderContents method.
OnPageChanging Raises the PageChanging event.
OnPageChanged Raises the PageChanged event.
GoToPage Raises the PageChanging and PageChanged events, jump to specified page.
LoadPostData Implements IPostBackDataHandler interface, processes postback data for the AspNetPager control.
RaisePostDataChangedEvent Implements IPostBackDataHandler interface, signals the AspNetPager control to notify the ASP.NET application that the state of the control has changed.
RaisePostBackEvent Implements IPostBackEventHandler Interface, notifies the AspNetPager control that caused the postback that it should handle an incoming postback event.

Events:

NameDescription
PageChanging Occurs when one of the pager buttons is clicked, but before the AspNetPager control handles the paging operation.
PageChanged Occurs when one of the pager buttons is clicked, but after the AspNetPager control handles the paging operation.

Remarks:

AspNetPager is a free custom paging control for ASP.NET web form application. It's independent of any underlying data sources and data controls. It's flexible and powerful, has many features, it support both post back and url paging.

In order to use AspNetPager control, at least specify the value of property and write event handlers for or events, you can bind and display data using data controls or write custom data displaying logics in these event handlers.

Example:

The following sample shows how AspNetPager can be used to add paging functionality to Repeater control:
    <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<%@Import NameSpace="System.Data"%>
<%@Import NameSpace="System.Data.SqlClient"%>
<script runat="server" Language="C#">
void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int totalOrders = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetOrderNumber");
            AspNetPager1.RecordCount = totalOrders;
            bindData();
        }
    }
 void bindData()
    {
        Repeater1.DataSource = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"P_GetPagedOrders2005",
            new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
            new SqlParameter("@pageSize", AspNetPager1.PageSize));
        Repeater1.DataBind();
    }
 void AspNetPager1_PageChanged(object src, EventArgs e)
    {
        bindData();
    }
</script>
<HTML><HEAD>
<TITLE> AspNetPager Samples </TITLE>
<META NAME="Author" CONTENT="Webdiyer (en.webdiyer.com)">
</HEAD>
<BODY>
<form runat="server">
        <asp:Repeater ID="Repeater1" runat="server">
        <HeaderTemplate>
        <table width="100%" border="1" cellspacing="0" cellpadding="4" style="border-collapse:collapse">
        <tr style="backGround-color:#CCCCFF"><th style="width:15%"><asp:Literal ID="Literal1" runat="server" Text="<%$Resources:LocalizedText,orderid%>" /></th><th style="width:15%"><asp:Literal ID="Literal3" runat="server" Text="<%$Resources:LocalizedText,orderdate%>" /></th><th style="width:30%"><asp:Literal ID="Literal5" runat="server" Text="<%$Resources:LocalizedText,companyname%>" /></th><th style="width:20%"><asp:Literal ID="Literal2" runat="server" Text="<%$Resources:LocalizedText,customerid%>" /></th><th style="width:20%"><asp:Literal ID="Literal4" runat="server" Text="<%$Resources:LocalizedText,employeename%>" /></th></tr>
        </HeaderTemplate>
        <ItemTemplate>
        <tr style="background-color:#FAF3DC">
        <td><%#DataBinder.Eval(Container.DataItem,"orderid")%></td>
        <td><%#DataBinder.Eval(Container.DataItem,"orderdate","{0:d}")%></td>
        <td><%#DataBinder.Eval(Container.DataItem, "companyname")%></td>
        <td><%#DataBinder.Eval(Container.DataItem,"customerid")%></td>
        <td><%#DataBinder.Eval(Container.DataItem,"employeename")%></td>
        </tr>
        </ItemTemplate>
		<FooterTemplate>
        </table>
        </FooterTemplate>
        </asp:Repeater>
  <webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" HorizontalAlign="right" PageSize="8" OnPageChanged="AspNetPager1_PageChanged">
        </webdiyer:AspNetPager>
		</form>
</BODY>
</HTML>
Stored procedure code:

CREATE PROCEDURE P_GetPagedOrders2005
	@startIndex INT, 
    @pageSize INT 
AS
begin
WITH orderList AS ( 
SELECT ROW_NUMBER() OVER (ORDER BY O.orderid DESC)AS Row, O.orderid,O.orderdate,O.customerid,C.CompanyName,E.FirstName+' '+E.LastName as EmployeeName 
from orders O
left outer join Customers C
on O.CustomerID=C.CustomerID
left outer join Employees E
on O.EmployeeID=E.EmployeeID)
SELECT orderid,orderdate,customerid,companyName,employeeName
FROM orderlist
WHERE Row between @startIndex and @startIndex+@pageSize-1
end