Aspnetpager Common Properties
It is recommended to encapsulate well and then call it easier
<webdiyer:aspnetpager id= "AspNetPager1" runat= "Server"
alwaysshow= "True"
Pagesize= "5"
Custominfosectionwidth= "20%"
Custominfotextalign= "Right"
firstpagetext= "First Page"
Horizontalalign= "left"
lastpagetext= "Last Page"
Navigationbuttontype= "Image"
nextpagetext= "Next Page"
Pageindexboxtype= "TextBox"
Pagingbuttonspacing= "8px"
prevpagetext= "Previous Page"
Showcustominfosection= "Right"
Showpageindexbox= "Always"
textafterpageindexbox= "Page"
Urlpaging= "true"
Textbeforepageindexbox= "Jump to the first"
Width= "97%"
onpagechanged= "Aspnetpager1_pagechanged" >
</webdiyer:aspnetpager>
Alwaysshow: The paging control is always displayed;
PageSize: Specifies the number of records to display per page;
Custominfosectionwidth: The width of the user-defined information area;
Custominfotextalign: User defined the alignment of the information area;
Firstpagetext: The text displayed on the first page button;
HorizontalAlign: Content horizontal alignment;
Lastpagetext: Text displayed on the last page button;
Navigationbuttontype: The type of the first page, the next page, the last page button;
NextPageText: The text displayed on the next page of the button;
Pageindexboxtype: Indicates the display type of page index box: There are two kinds of textbox and DropDownList;
Pagingbuttonspacing: The spacing of the navigation page buttons;
Prevpagetext: The displayed text of the previous page button;
Showcustominfosection: Displays the current page and the total page information, default is not displayed, the value is left when displayed in front of the page index, right when displayed in the page index;
Showpageindexbox: Specifies how the page index text box or drop-down box is displayed;
Textafterpageindexbox: Specifies the text after the page index text box or drop-down box;
Urlpaging: Is enough to use the URL to pass the paging way to page;
Textbeforepageindexbox: Specifies the text that appears before the page index text box or drop-down box;
Width: The height of the control;
Custominfohtml: Specifies the user-defined HTML information text to display in the user's custom information area
Using System;
Using System.Configuration;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Xml.Linq;
Using System.Data.SqlClient;
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
Bind ();
}
private void Bind ()
{
int pageindex = 1;
int pagenum = aspnetpager1.pagesize;
if (request["page"]! = NULL)
{
pageindex =convert.toint32 (request["page"]);
}
DataSet ds = new DataSet ();
SqlConnection con = new SqlConnection (configurationmanager.connectionstrings["Constr"]. ToString ());
SqlConnection con1 = new SqlConnection (configurationmanager.connectionstrings["Constr"]. ToString ());
SqlDataAdapter SDA = new SqlDataAdapter ("select Top (@pagenum) * from Pagetest where ID not in (select Top (@pagenum * (@pa geindex-1))) (ID from pagetest) ", con);
Sda. SelectCommand.Parameters.AddWithValue ("Pagenum", pagenum);
Sda. SelectCommand.Parameters.AddWithValue ("pageindex", pageindex);
Sda. Fill (DS);
SqlCommand cmd = new SqlCommand ("SELECT count (*) from Pagetest", con1);
Con1. Open ();
Aspnetpager1.recordcount =convert.toint32 (cmd. ExecuteScalar ());
Con. Close ();
aspnetpager1.custominfohtml = "Total" + aspnetpager1.recordcount + "Record" + Aspnetpager1.currentpageindex + "/" + AspNetP Ager1. PageCount;
Gridview1.datasource = ds. Tables[0]. DefaultView;
Gridview1.databind ();
}
protected void Aspnetpager1_pagechanged (object sender, EventArgs e)
{
Bind ();
}
}
In-depth analysis of CurrentPageIndex, RecordCount, PageCount, PageSize:
PageCount:
public int PageCount
{
Get
{
if (this. RecordCount = = 0)
{
return 1;
}
return (int) math.ceiling (double) ((double) this. RecordCount)/(double) this. (PageSize)));
}
}
RecordCount
public int RecordCount
{
Get
{
if (this.clonefrom! = null)
{
return this.cloneFrom.RecordCount;
}
Object obj2 = this. viewstate["Recordcount"];
if (obj2! = null)
{
return (int) obj2;
}
return 0;
}
Set
{
This. viewstate["Recordcount"] = value;
}
}
CurrentPageIndex:
public int CurrentPageIndex
{
Get
{
if (this.clonefrom! = null)
{
return this.cloneFrom.CurrentPageIndex;
}
Object obj2 = this. viewstate["CurrentPageIndex"];
int num = (OBJ2 = = null)? 1: ((int) obj2);
if (num > this. PageCount) && (this. PageCount > 0))
{
return this. PageCount;
}
if (num < 1)
{
return 1;
}
return num;
}
Set
{
int pagecount = value;
if (PageCount < 1)
{
PageCount = 1;
}
else if (PageCount > this. PageCount)
{
PageCount = this. PageCount;
}
This. viewstate["CurrentPageIndex"] = PageCount;
}
}
PageSize:
public int PageSize
{
Get
{
int num;
if (!string. IsNullOrEmpty (this. Urlpagesizename) &&!base. DesignMode) && (int. TryParse (this. Page.request.querystring[this. Urlpagesizename], out num) && (num > 0)))
{
return num;
}
if (this.clonefrom! = null)
{
return this.cloneFrom.PageSize;
}
Object obj2 = this. viewstate["PageSize"];
if (obj2! = null)
{
return (int) obj2;
}
return 10;
}
Set
{
This. viewstate["PageSize"] = value;
}
}
Alwaysshow
Gets or sets a value that specifies whether Aspnetpager pagination is always displayed, even if the data to be paged has only one page.
Currentpagebuttonposition
The position of the current page number button in all the number paging buttons, selectable values are: Beginning (front), End (last), Center (center), and fixed (default)
CurrentPageIndex
Gets or sets the index of the currently displayed page.
Firstpagetext
Gets or sets the text that is displayed for the first-page button.
Lastpagetext
Gets or sets the text that is displayed for the last-page button.
NextPageText
Gets or sets the text that is displayed for the next-page button.
Prevpagetext
Gets or sets the text displayed for the previous page button.
PageSize
Gets or sets the number of items to display per page. (This value Gets or sets the number of items that the data rendering control wants to display every time the data is displayed in the data table, Aspnetpager calculates the total pages required for all data, that is, the value of PageCount, based on that value and RecordCount. )
Pageindexboxtype:
or set the display type of the page index box, which can be a text box that allows the user to enter manually and a drop-down box that can be selected only.
Morebuttontype
Gets or sets the "more Pages" (... ) The type of the button that is valid only if Pagingbuttontype is set to image.
Urlpageindexname
Gets or sets the name of the parameter in the URL that represents the page index to pass when the URL paging method is enabled.
Urlpagesizename
Gets or sets the name of the parameter in the URL that specifies the number of records to display per page, or the value is not empty or URL
The value of the parameter corresponding to the value is greater than 0, the PageSize property uses the value of the parameter as the number of records to display per page.
Urlpaging
Gets or sets whether URLs are enabled to pass paging information.
Textafterpageindexbox
Gets or sets the text string value after the page index page index entry text box or drop-down box.
Textbeforepageindexbox
Gets or sets the text string value of the page index page index before the input text box or drop-down box.
Navigationbuttontype
Gets or sets the type of the first page, previous page, next page, and last page button, which is only valid if Pagingbuttontype is set to image.
Navigationtooltiptextformatstring
Gets or sets the format of the navigation button ToolTip text.
NextPageText
Gets or sets the text that is displayed for the next-page button.
Numericbuttoncount
Gets or sets the number of numeric buttons that are displayed simultaneously in the pager element of the Aspnetpager control.
Numericbuttontextformatstring
Gets or sets the display format of the text on the page index value navigation button.
Numericbuttontype
Gets or sets the type of the pager value button that is valid only if Pagingbuttontype is set to image.
PageCount
Gets the total number of pages required for all records to be paged.
Pageindexboxclass
Gets or sets the CSS class name that is applied to the page index input text box or drop-down box.
Pageindexboxstyle
Gets or sets the CSS style text for the page index input text box or drop-down box.
Pageindexboxtype
Pageindexoutofrangeerrormessage
Gets or sets the error message that is displayed on the client when the user enters a page index that is out of range (greater than the maximum page index or less than the Minimum page index).
PageSize Gets or sets the number of items displayed per page.
Pagesremain gets the total number of pages that are not displayed after the current page. Pagingbuttonlayouttype
Specify page navigation buttons (numbers and previous, next, first, last) layouts that you can include in the <li> or <span> tab to easily apply CSS styles, which are not included in any labels by default.
Pagingbuttonspacing
Gets or sets the spacing between paging navigation buttons.
Pagingbuttontype
Gets or sets the type of pager button, even if it is text or a picture.
Showfirstlast
Gets or sets a value that indicates whether the first page and last page buttons are displayed in the pager element.
Shownavigationtooltip
Gets or sets a value indicating whether the ToolTip is displayed when the mouse pointer hovers over the navigation button.
Showpageindex
Gets or sets a value that indicates whether the page index value button is displayed in the pager element.
Showpageindexbox Showprevnext
Gets or sets a value that indicates whether the previous and next page buttons are displayed in the pager element
Aspnetpager Common Properties (recently used for paging properties)