ASPNETPager common attributes (paging attributes recently used) and aspnetpager Paging
ASPNETPagerCommon attributes
It is recommended to encapsulate the data, and then it is easier to call the data.
<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"
Width = "97%"
Onpagechanged = "AspNetPager1_PageChanged">
</Webdiyer: aspnetpager>
Alwaysshow: always display paging controls;
PageSize: specify the number of records displayed per page;
Custominfosectionwidth: the width of the custom information area;
Custominfotextalign: Alignment of the custom information area;
Firstpagetext: Text displayed on the button on the first page;
Horizontalalign: horizontal content alignment;
Lastpagetext: The text displayed on the last page;
Navigationbuttontype: the type of the buttons on the first, next, and last pages;
Nextpagetext: Text displayed on the next page;
Pageindexboxtype: indicates the display type of index boxes on the page: TextBOX and dropdownlist;
Pagingbuttonspacing: The spacing of buttons on the navigation page;
Prevpagetext: Text displayed on the previous page;
Showcustominfosection: displays the current page and total page information. It is not displayed by default. If the value is LEFT, it is displayed before the page index and right after the page index;
Showpageindexbox: Specify the display mode of the index text box or drop-down box;
Textafterpageindexbox: Specifies the text in the index text box or after the drop-down box;
UrlPaging: it is enough to use the URL to pass pages;
Textbeforepageindexbox: Specifies the text displayed in the index text box or in front of the drop-down box;
Width: the width of the control;
CustomInfoHTML: Specifies the custom HTML text to be displayed in the User-Defined 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 * (@ pageindex-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 + "/" + AspNetPager1.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) 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 the AspNetPager page is always displayed, even if the data to be paged has only one page.
CurrentPageButtonPosition
Position of the number button on the current page in all numeric pagination buttons. Optional values: Beginning (Beginning), End (last), Center (Center), and Fixed (Fixed by default)
CurrentPageIndex
Gets or sets the index of the current display page.
FirstPageText
Obtain or set the text displayed on the first page.
LastPageText
Obtain or set the text displayed on the last page.
NextPageText
Obtain or set the text displayed on the next page.
PrevPageText
Obtain or set the text displayed on the previous page.
PageSize
Obtain or set the number of items displayed on each page. (This value gets or sets the number of data items in the data presentation control each time to display the data items in the data table. AspNetPager calculates the total number of pages required to display all data based on this value and RecordCount, that is, the PageCount value. )
PageIndexBoxType:
Alternatively, you can set the display type of the index box, which can be a text box that you can manually enter and a drop-down box that can only be selected.
MoreButtonType
Gets or sets the type of the "more pages" (...) button. This value is valid only when PagingButtonType is set to Image.
UrlPageIndexName
Obtain or set the parameter name of the page index to be passed in the Url when the url paging mode is enabled.
UrlPageSizeName
Gets or sets the name of the parameter that specifies the number of records displayed on each page in the Url, or the value is not empty or the Url
If the value of this parameter is greater than 0, the PageSize attribute uses the value of this parameter as the number of records displayed on each page.
UrlPaging
Obtain or set whether to enable url to pass paging information.
TextAfterPageIndexBox
Gets or sets the text string value of the input text box or the drop-down box of the index on the page.
TextBeforePageIndexBox
Gets or sets the text string value before the input text box or drop-down box of the index on the page.
NavigationButtonType
Obtains or sets the types of buttons on the first, previous, next, and last pages. This value is valid only when PagingButtonType is set to Image.
NavigationToolTipTextFormatString
Gets or sets the format of the prompt Text of the navigation button tool.
NextPageText
Obtain or set the text displayed on the next page.
NumericButtonCount
Gets or sets the number of numeric buttons simultaneously displayed in the page navigation element of the AspNetPager control.
NumericButtonTextFormatString
Obtain or set the text display format on the page index value navigation button.
NumericButtonType
Gets or sets the type of the page navigation value button. This value is valid only when PagingButtonType is set to Image.
PageCount
Obtain the total number of pages required for all records to be paged.
PageIndexBoxClass
Gets or sets the CSS class name applied to the input text box or drop-down box of the page index.
PageIndexBoxStyle
Gets or sets the CSS style text in the input text box or drop-down box of the page index.
PageIndexBoxType
PageIndexOutOfRangeErrorMessage
Obtain or set the error message displayed on the client when the page index entered by the user is out of the range (greater than or less than the maximum page index.
PageSize gets or sets the number of items displayed on each page.
PagesRemain gets the total number of pages not displayed after the current page. PagingButtonLayoutType
Specify the layout of pagination navigation buttons (numbers and upper pages, lower pages, home pages, and end pages). You can include these elements in the <li> or <span> label to facilitate the application of CSS styles, by default, tags are not included.
PagingButtonSpacing
Gets or sets the spacing between tabs and navigation buttons.
PagingButtonType
Obtain or set the type of the paging navigation button, that is, text or image.
ShowFirstLast
Gets or sets a value indicating whether to display the first and last buttons in the page navigation element.
ShowNavigationToolTip
Gets or sets a value indicating whether a tooltip is displayed when the mouse pointer is hovering over the navigation button.
ShowPageIndex
Gets or sets a value indicating whether to display the page index value button in the page navigation element.
ShowPageIndexBox ShowPrevNext
Gets or sets a value indicating whether to display the previous page and next page buttons in the page navigation element.