Today, I studied the following asp.net can be customized pagination, the use of a very cool, below to introduce you.
With the help of the data-bound control provided by ASP.net, we do not need too much code, even do not require code, as long as in the VS2005 drag a few controls, the setting of some properties, you can achieve in the era of Asp need to do a lot of work to achieve the paging function. However, in practical applications, especially in Web site programs, we often need a richer user interface, and data controls like DataList or GridView often fail or are difficult to meet our requirements. At this point, we often turn to the Repeater control, so that we still face pagination and the problems it displays.
This article is not about how to do database paging, but focuses on how to achieve a customizable way to get page numbers, get paths, display page links, and implement code reuse by building a user control. If you are a beginner, you can learn from my implementation; If you are already a master, you may wish to propose the deficiencies of the design and improve the opinion.
This article is about the implementation of the interface, because I wrote this article with the interface, but I later provided a better way to use inheritance to implement, I provided two versions of the code download, you can compare each other reference.
Control composition
In order to quickly mention the interest of everyone, you can click on this link to see the actual effect:
Http://www.tracefact.net/Demo/Pager/Default.aspx
Iurlmanager interface
Think about it. If you are designing a reusable paging user control, what are the problems you face? Each person gets a different way of getting the page number, for example, your site URL might be a default.aspx?page=1 like this, and the other site's URL is such a default.aspx?p=1. Some may not use QueryString to get page numbers at all, their URLs may be such default-1.aspx, default-2.aspx, and so on. When you get page numbers differently, the way you create a link address based on a page number is naturally different. In accordance with the idea of package change, we should take the change part out and build a Iurlmanager interface:
Public interface Iurlmanager
{
int currentpageindex{get;} Current page number
string getpageurl (int pageIndex); Get page path by page number
In fact, the current page should not be larger than the total number of pages, so getting the CurrentPageIndex property of the current pages requires the total number of pages to be learned, and the total page count is usually calculated from the numbers of records and paging sizes, which should actually be the case:
Public interface Iurlmanager
{
int currentpageindex{get;} Current page number
string getpageurl (int pageIndex); Gets the page path
int PageCount {get;} based on the page number Total pages
int RecordCount {get;} Total records
int PageSize {get;} Paging Size
}