// This source code is for learning reference only, not for any commercial purposes;
// If you need to modify and re -compile the control, retain the copyright information of the complete source code!
// For information about control upgrade and new control release information, please pay attention to www.webdiyer.com.
using system;
using system.io;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlControls;
USING SYSTEM.COLLECTIONS.SPECIALIZED;
using system.text;
using system.componentmodel;
USING SYSTEM.COMPONENTMOL.DESIGN;
using system.collections;
namespace wuqi.webdiyer
{{
#Region aspnetpager Server Control
#Region control description and example
/// <summary>
/// For server controls for data paging data in the ASP.NET Web application.
/// </summary>
/// <ReMarks> Unlike the DataGrid control, the ASPNETPAGER paging control itself does not display any data, but only display the page navigation element. The display method on the page has nothing to do with the control. This control can paged the DataGrid, DataList, Repeater, and custom controls. With SQL storage procedures, the paging performance is significantly improved compared to the DataGrid paging, especially when the amount of data can be increased by several times when the amount of data is large!
/// <p> ASPNETPAGER 2.0 newly added the function of paging through the URL, which allows visitors to directly enter the corresponding URL to access any page, and the search engine can also directly retrieve each page. Function, this cannot be realized. </p>
/// <p> To use the ASPNETPAGER paging control, at least it must specify its <See Cref = "RecordCount"/> attribute, specify and write the processing program of the <see Cref = "PageChanged"/> event.
/// <see Cref = "RecordCount"/> The attribute specifies the total number of all data to be paged in the paging. Any content.
/// If the <see Cref = "PageChanged"/> event processing program is not specified and written, then when the user clicks the page navigation element or the hand -style input page index in the page index text box and submit it Page.
/// The paging method of the ASPNETPAGER control is basically the same as that of DataGrid, that is, in its <see Cref = "PageChanged"/> event processing program, the <see Cref = "PageChangedEventargs" of <See Cref = " PageChangedEventargs.newpageINDEX "/> value is assigned to the <see Cref =" CurrentPageINDEX "/> attribute of <See Cref =" CurrentPageINDEX "/>, and then re -bind the new data and data display controls. </p> </remarks>
/// <EXAMPLE> The following examples show how to use ASPNETPAGER to page the DataGrid.
/// <code> <! [cdata [cdata [
/// <%@ page language = "c#"%>
/// <%@ Import namespace = "System.data"%>
/// <%@Import namespace = "System.data.sqlclient"%>
/// <%@Import namespace = "System.configuration"%>
/// <%@register tagprefix = "webdiyer" namespace = "wuqi.webdiyer" assembly = "aspnetpager"%>
/// <html>
/// <head>
/// <Title> WELCOME to webdiyer.com </Title>
/// <script runat = "server">
/// sqlconnection conn;
/// sqlcommand cmd;
/// void page_load (Object SRC, EventArgs E)
/// {
// conn = new sqlconnection (configurationSettings.appsettings ["connstr"];
/// if (! Page.ispostback)
/// {
/// cmd = new sqlcommand ("getNews", conn);
/// cmd.commandtype = CommandType.storedProceDure;
/// cmd.parameters.add ("@posgeindex", 1);
/// cmd.parameters.add ("@PageSize", 1);
/// cmd.parameters.add ("@Docount", TRUE);
// conn.open ();
/// pager.Recordcount = (int) cmd.executescalal ();
// conn.close ();
/// binddata ();
///}
///}
///
/// void binddata ()
/// {
/// cmd = new sqlcommand ("getNews", conn);
/// cmd.commandtype = CommandType.storedProceDure;
/// cmd.parameters.add ("@posgeindex", pager.currenTPageIndex);
/// cmd.parameters.add ("@PageSize", pager.pageSize);
/// cmd.parameters.add ("@docount", false);
// conn.open ();
/// datagrid1.dataSource = cmd.executeReader ();
/// datagrid1.dataBind ();
// conn.close ();
/// pager.custominFotext = "Record Total: <font color =" Blue "> <b>"+Pager.recordcount.tostring ()+"</font>" ";
/// pager.custominfotext+= "Total page Number: <font color =" blue "> <b>"+pager.pageCount.tostring ()+"</font>" ";
/// pager.custominfotext+= "Current page: <font color =" red "> <b>"+pager.currentpageindex.tostring ()+"</b> </font>"
///}
/// Void Changepage (Object SRC, PageChangedeventargs E)
/// {
/// pager.currentpageindex = e.newpageindex;
/// binddata ();
///}
/// </script>
/// <meta http-equiv = "Content-Language" Content = "ZH-CN">
/// <meta http-equiv = "Content-Type" Content = "Text/HTML; Charset = GB2312">
/// <meta name = "general" content = "editplus">
/// <meta name = "author" content = "webdiyer ([Email Protected])"> ">">
/// </head>
/// <body>
/// <FORM RUNAT = "Server" ID = "FORM1">
/// <asp: datagrid id = "datagrid1" runat = "server"/>
/// <webdiyer: aspnetpager ID = "Pager"
/// runat = "server"
/// pageSize = "8"
///numericbuttoncount = "8"
/// showCustomInFosection = "Left"
/// pagingbuttonspacing = "0"
/// showinputbox = "always"
/// cssclass = "MyPager"
/// horizontalalally = "Right"
/// OnPageChanged = "Changepage"
/// submitButtontext = "Turn to"
///numericButtontextFormatstring = "[{0}]"/>
/// </form>
/// </body>
/// </html>
///]]>
/// </code>
/// <p> The SQL Server storage procedure used in this example: </p>
/// <code>
/// <! [cdata [cdata [
/// Create Procedure GetNews
/// (@pageSize int,
/// @pageindex int,
@Docount bit)
/// as
/// set nocount on
/// if (@docount = 1)
/// select count (id) from news
/// else
/// begin
/// DecLARE @INDEXTABLE TABL
/// Declare @pageLowerBound int
/// DecLARE @Pageupperbound int
/// set @Pagelowerbound = (@Pageindex-)*@PageSize
/// set @[Email Protected] [Email Protected]
/// set rowcount @Pageupperbound
/// Insert Into @indextable (NID) SELECT Id FROM News Order by Addtime Desc
/// select o.id, o.source, o.title, o.addtime from news
/// and t.id> @pageelowerbound and t.id <= @pageupperbound order by t.id
/// end
/// set nocount off
/// GO
///]]>
/// </code> </example>
#Endregion
[DefaultProperty ("PageSize")]
[DefaultEvent ("PageChanged")]
[PARSECHILDRN (FALSE)]
[PersistChildren (FALSE)]
[description ("" pagination control for ASP.NET Web applications ")]]]]]]]]]]
[Designer (Typeof (PagerDesigner)]]
[ToolBoxData (<{0}: aspnetpager runat = Server> </{0}: aspnetpager> ")]
Public Class ASPNETPAGER: Panel, InamingContainer, iPostBackeventhandler, iPostBackDatahandler
{{
Private String CSSClassName;
Private String urlpageindexname = "Page";
Private Bool urlpaging = false;
Private String inputpageIndex;
Private String Currenturl = NULL;
Private nameValueCollection urlparams = null; #Region Properties #Region Navigation Buttons /// <Summary>
/// Get or set a value. The value of the value is that when the mouse pointer is hovering on the navigation button, is it a display tool prompt.
/// </summary>
[Browsable (True),
category ("Navigation button"), DefaultValue (True), Description ("Specifies when the mouse stays on the navigation button, is the display tool prompt"]]]]]])]
Public Bool ShownavigationTooltip
{{
get
{{
object obj = viewState ["shownavigationTooltip"];
Return (obj == null)? true: (BOOL) Obj;
}
set
{{
ViewState ["ShownavigationTooltip"] = value;
}
} /// <summary>
/// Get or set the navigation button tool to prompt the text format.
/// </summary>
[Browsable (True),
Category ("Navigation button"),
DefaultValue ("Turn to page No. {0}"),
Descripting ("Page Navigation button Tools Reminder Text Format")]
Public String
{{
get
{{
object obj = viewState ["navigationTooltiptextFormatstring"];
Return (obj == null)? "Turn to page {0} page": (string) obj;
}
set
{{
string tip = value;
if.trim (). Length <1 && tip.indexof ("{0}") <0)
tip = "{0}";
ViewState
}
} /// <summary>
/// Get or set a value. This value indicates whether the page index button is replaced with Chinese numbers.
/// </summary>
/// <lmarks>
/// When setting this value to TRUE and not using the picture button, the value of the page index button 1, 2, 3, etc. will be replaced by Chinese characters first, two, and three.
/// </remarks>
[Browsable (True),
Category ("Navigation button"),
DefaultValue (FALSE),
Descripting ("Whether the page index value button is replaced by Chinese numbers first, second, and third,"]]
Public BOOL CHINESEPAGEINDEX
{{
get
{{
object obj = viewState ["chinesePageIndex"];
Return (obj == null)? False: (BOOL) Obj;
}
set
{{
ViewState ["ChinesePageINDEX"] = Value;
}
} /// <summary>
/// Get or set the display format of the text on the number navigation button.
/// </summary>
/// <value>
/// String, specify the display format of the text on the page index value of the page, the default value is <see Cref = "String.empty"/>, that is, the property is not set. </value>
/// <lmarks>
/// Use NumericButtonTextFormatString Properties to specify the display format of the indexed value button. If the value of the index button is not set when it is not set, the text will be: 1 2 3 ...
/// If the value is set to "[{0}]", the index text will be displayed as: [1] [2] [3] ..., set the value to "-{0}-", and then Turn the index text to: -1--2- -3- ...
/// </remarks>
[Browsable (True),
defaultValue (""),,
Category ("Navigation button"),
Descripting ("Display Format of the Text on the Page Index Numerical button")]
Public String NumericButtontextFormatstring
{{
get
{{
object obj = viewState
Return (obj == null)? String.empty: (string) obj;
}
set
{{
ViewState ["NUMERICBUTTONTEXTEXTFORMATRING"] = value;
}
} /// <summary>
/// Get or set the type of paging navigation button, even if text is still picture.
/// </summary>
/// <lmarks>
/// To use the picture button, you need to prepare the following pictures: ten values from 0 to 9 (when ShowpageIndex is set to True), the first page, previous page, the next page, the last page and more more and more Page (...) Five buttons pictures (when Showfirstlast and Showprevnext are set to True),
/// If the numerical button of the current page index is needed to be different from other page index numeric buttons, you need to prepare the button picture of the current page index;
/// If the picture of the disabled first page, last page, next page, and last page is different from the normal button picture, you need to prepare the pictures of these four buttons in the disabled state;
/// <p> <b> The naming rules of the picture file are as follows: </b> </p>
/// <p> From 0 to 9 ten numerical buttons, the picture must be named "value+ButtonImageNameExtExExEnses+ButtonImageExtentation".
/// ButtonImageExtenting is the suffix name of the picture file, such as .gif or .jpg, etc., any picture file types that can be displayed in the browser. For example, the picture file of the page index "1" can be named "1.gif" or "1.jpg",
/// When you have two or more sets of picture files, you can distinguish different sets of different sets of pictures by specifying the ButtonImageNameExtent attribute value. If the first set of pictures can be set without ButtonImageNameExtentation, the picture file name is similar to "1.gif". , "2. GIF", etc., and the second set of pictures is set for "F", the name of the picture file is similar to "1F.gif", "2F.gif" and so on. </p>
/// <p> The picture file name of the first page button starts with "FIRST". The picture name of the previous page button starts with "Prev". Beginning with "LAST", more page buttons start with "More". Whether the ButtonimageNameExketnsion uses the ButtonImageNameExtension depends on the settings of the numerical button and whether there are more pictures. </p>
/// </remarks>
/// <EXAMPLE>
/// The following code fragment example If using the picture button:
/// <p>
/// <code> <! [cdata [cdata [
/// <webdiyer: aspnetpager runat = "server"
/// ID = "pager1"
/// OnPageChanged = "Changepage"
/// pagingButtontype = "Image"
/// ImagePath = "Images"
/// buttonImageNameExtent = "n"
/// disabledbuttonimagenameeXTENSION = "G"
/// ButtonImageExtent = "GIF"
/// CPIBUTTONIMAGENAMEEXENSION = "R"
/// pagingbuttonspacing = 5/>
///]]>
/// </code>
/// </p>
/// </Example>
[Browsable (True),
DefaultValue (PagingButtonType.text),
Category ("Navigation button"),
Description
public pagingButtonType pagingButtisepe
{{
get
{{
object obj = viewState
Return (obj == null)? PagingButtonType.text: (pagingButtonType) obj;
}
set
{{
ViewState
}
} /// <summary>
/// Get or set the type of the navigation numerical button, which is valid only when the PagingButtonType is set to the image.
/// </summary>
/// <lmarks>
/// When you set the pagingButtonType to Image, when you do not want the page index numeric button to use the picture, you can set the value to Text, which will make the page index data button use the text instead of the picture button.
/// </remarks>
[Browsable (True),
DefaultValue (PagingButtonType.text),
Category ("Navigation button"),
Descripting ("Type of" Page Navigation Numeral Numerical button ")]]
public pagingButTONTYPE NUMERICBUTTONTYPE
{{
get
{{
object obj = viewState
Return (obj == null)? PagingButtonType: (PagingButtype) obj;
}
set
{{
ViewState ["NUMERICBUTTONTYPE"] = Value;
}
} /// <summary>
/// Get or set the type of the first page, last page, next page and the last page. This value is only valid when PagingButtonType is set to images.
/// </summary>
/// <lmarks>
/// When you set the pagingButtonType to Image but do not want to use the picture for the first, next page, next page, and last page, you can set the value to Text, which will make the previous four buttons on the previous four buttons Use text instead of the picture button.
/// </remarks>
[Browsable (True),
Category ("Navigation button"),
DefaultValue (PagingButtonType.text),
Description
public pagingButtonType
{{
get
{{
object obj = viewState ["navigationButtonType"];
Return (obj == null)? PagingButtonType: (PagingButtype) obj;
}
set
{{
ViewState ["NavigationButtonType"] = Value;
}
} /// <summary>
/// Get or set the type of "more pages" (...) button, which is only valid when the PagingButtonType is set to image.
/// </summary>
/// <lmarks>
/// When you set the PagingButtonType to Image but do not want more pages (...) button to use pictures, you can set this value to Text, which will make more page buttons use text instead of the picture button.
/// </remarks>
[Browsable (True),
Category ("Navigation button"),
DefaultValue (PagingButtonType.text),
Descripting ("More Pages" (...) button type ")]
public pagingButTonType morebuttonpe
{{
get
{{
object obj = viewState ["Morebuttisepe"];
Return (obj == null)? PagingButtonType: (PagingButtype) obj;
}
set
{{
ViewState ["Morebuttisepe"] = Value;
}
} /// <summary>
/// Get or set the distance between the paging navigation button.
/// </summary>
[Browsable (True),
Category ("Navigation button"),
DefaultValue (Typeof (Unit), "5px"),
Description
public unit pagingButtonSpacing
{{
get
{{
object obj = viewState ["pagingbuttonspacing"];
Return (obj == null)? Unit.pixel (5): (unit.parse (obj.tostring ()));
}
set
{{
ViewState ["pagingbuttonspacing"] = value;
}
} /// <summary>
/// Get or set a value, which indicates whether the first and last page buttons are displayed on the page navigation element.
/// </summary>
[Browsable (True),
Descripting
Category ("Navigation button"),
DefaultValue (True)]
Public BOOL Showfirstlast
{{
get
{{
object obj = viewState ["showfirstlast"];
Return (obj == null)? true: (BOOL) Obj;
}
set {ViewState ["showfirtlast"] = value;}
} /// <summary>
/// Getting or setting a value, this value indicates whether the previous page and the next page are displayed in the page navigation element.
/// </summary>
[Browsable (True),
Descripting
Category ("Navigation button"),
DefaultValue (True)]
Public BOOL Showprevnext
{{
get
{{
object obj = viewState ["showprevnext"];
Return (obj == null)? true: (BOOL) Obj;
}
set {ViewState ["showprevnext"] = value;}
} /// <summary>
/// Get or set a value that indicates whether the page index value button is displayed in the page navigation element.
/// </summary>
[Browsable (True),
Descripting ("Whether the value button is displayed in the page navigation element"),
Category ("Navigation button"),
DefaultValue (True)]
Public Bool ShowpageIndex
{{
get
{{
object obj = ViewState ["showpageindex"];
Return (obj == null)? true: (BOOL) Obj;
}
set {ViewState ["showpageindex"] = value;}
} /// <summary>
/// Get or set to the text displayed by the first page button.
/// </summary>
[Browsable (True),
description ("Text displayed on the first page button"),
Category ("Navigation button"),
defaultValue ("<font face =" webdings "> 9 </font>")]]
public string firstpagetext
{{
get
{{
object obj = viewState ["firstpagetext"];
Return (obj == null)? "<font face =" webdings "> 9 </font>": (string) obj;
}
set {ViewState ["firstpagetext"] = value;}
} /// <summary>
/// Get or set to text displayed in the previous page button.
/// </summary>
[Browsable (True),
description ("text displayed on the previous page button"),
Category ("Navigation button"),
defaultValue ("<font face =" webdings "> 3 </font>")]]
Public String Prevagetext
{{
get
{{
object obj = viewState ["prevagetext"];
Return (obj == null)? "<font face =" webdings "> 3 </font>": (string) obj;
}
set {ViewState ["PrevpageText"] = value;}
} /// <summary>
/// Get or set the text displayed by the next page.
/// </summary>
[Browsable (True),
description ("Text displayed on the next page button"),
Category ("Navigation button"),
defaultValue ("<font face =" webdings "> 4 </font>")]]
Public String NextPageText
{{
get
{{
object obj = viewState ["nextPagetext"];
Return (obj == null)? "<font face =" webdings "> 4 </font>": (string) obj;
}
set {ViewState ["NextPageText"] = value;}
} /// <summary>
/// Get or set the text displayed as the last page button.
/// </summary>
[Browsable (True),
description ("Text displayed on the last page button"),
Category ("Navigation button"),
defaultValue ("<font face =" webdings ">: </font>")]]
Public String LastPageText
{{
get
{{
object obj = viewState ["lastpagetext"];
Return (obj == null)? "<font face =" webdings ">: </font>": (string) obj;
}
set {ViewState ["LastPageText"] = value;}
} /// <summary>
/// Get or set in the number of numerical buttons displayed at the same time in the page navigation element in the <see Cref = "ASPNETPAGER"/> control.
/// </summary>
[Browsable (True),
Descripting
Category ("Navigation button"),
defaultValue (10)]
Public int NumericButtoncount
{{
get
{{
object obj = viewState ["numericButtoncount"];
Return (obj == null)? 10: (int) obj;
}
set {ViewState ["NumericButtoncount"] = value;}
} /// <summary>
/// Get or set a value that specifies whether the disabled buttons are displayed.
/// </summary>
/// <lmarks>
/// This value is used to specify whether the disabled pagination navigation button is displayed. When the current page is the first page, the first and previous page buttons will be disabled. When the current page is the last page, the next page will be The last page button will be disabled, the banned buttons have no link, and click on the button will not have any effect.
/// </remarks>
[Browsable (True),
Category ("Navigation button"),
Descripting ("Whether to show the disabled button"),
DefaultValue (True)]
Public BOOL ShowdisableDbuttons
{{
get
{{
object obj = viewState ["showdisabledbutton"];
Return (obj == null)? true: (BOOL) Obj;
}
set
{{
ViewState ["Showdisabledbuttons"] = value;
}
}
#Endregion
#Region Image Buttons
/// <summary>
/// Get or set the path of the picture file when using the picture button.
/// </summary>
[Browsable (True),
Category ("Image button"),
Descripting ("When using the picture button, specify the path of the picture file"), "),),
defaultValue (null)]
Public String ImagePath
{{
get
{{
string imgpath = (string) viewState ["imagepath"];
if (IMGPATH! = Null)
imgpath = this.RSOLVEURL (imgpath);
Return imgpath;
}
set
{{
string imgpath = value.trim (). Replace ("", "/");
ViewState ["ImagePath"] = (imgpath.endswith ("/")? Imgpath: imgpath+"/";
}
}
/// <summary>
/// Get or set when using the picture button, the type of the picture, such as GIF or JPG, this value is the suffix name of the picture file.
/// </summary>
[Browsable (True),
Category ("Image button"),
defaultValue (". gif"),
Description ("When using the picture button, the type of the picture, such as GIF or JPG, this value is the suffix name of the picture file")]
Public String ButtonImageExtent
{{
get
{{
object obj = viewState ["ButtonImageExtent"];
Return (obj == null)? "GIF": (String) obj;
}
set
{{
string ext = value.trim ();
ViewState ["ButtonImageExtension"] = (ext.startswith (".")? EXT: ("."+EXT);
}
}
/// <summary>
/// Get or set the suffix string of the custom picture file name to distinguish the different types of buttons.
/// </summary>
/// <Remarks> <Note> Note: </not> This value is not a file suffix, but a string added to the picture name to distinguish different picture files, such as::
/// There are currently two sets of buttons, one of which "1" can be "1F.gif", and the picture name of the "1" in the other set can be "1N.gif", of which F and N are ButtonImagenameextension. </remarks>
[Browsable (True),
defaultValue (null),
Category ("Image button"),
Descripting ("The suffix of the" customized picture file name), such as the buttonImagenameXketency of the picture "1F.gif" is "F" ")]]]]]]]]
Public String ButtonImageenameEXTENSION
{{
get
{{
Return (String) ViewState
}
set
{{
ViewState ["ButtonimagenameExtension"] = value;
}
}
/// <summary>
/// Get or set the picture name suffix of the current page index button.
/// </summary>
/// <lmarks>
/// When <see Cref = "PagingButtonType"/> is set to Image, this attribute allows you to set the picture name suffix character used by the current page index button, so the current page index buttons can be used different from other page index buttons. The picture, if the value is not set, the default value is <see Cref = "ButtonimageNameExtent"/>, that is, the current page index button is used as the same picture as other page index buttons.
/// </remarks>
[Browsable (True),
defaultValue (null),
Category ("Image button"),
Descripting ("Picture Name Faculture String of the current page index button")]
Public String CPIBUTTONIMAGNAMEEXTENSION
{{
get
{{
object obj = viewState
Return (obj == NULL)? ButtonimageNameeXTENSION: (String) Obj;
}
set
{{
ViewState ["CPIBUTTONIMAGENAMEEXENSION"] = value;
}
}
/// <summary>
/// Get or set the disabled page navigation button picture name suffix string.
/// </summary>
/// <lmarks>
/// When <see Cref = "PagingButtonType"/> is set to Image, this value allows you to set the page navigation button (including the first page, the previous page, the previous page, the previous page, the previous page, the previous page, The picture file name suffix string of the next page and the last page of the last page, so the disabled page navigation button can be different from the normal page navigation button. If this value is not set, the default value is <see Cref = "ButtonimagerExtent"/>, that is, the disabled page navigation button uses the same picture as the normal page navigation button.
/// </remarks>
[Browsable (True),
defaultValue (null),
Category ("Image button"),
Descripting ("Picture Name Volume String of the Disabled Page Navigation button")]
Public String DisabledButtonimaGenameEXTENSION
{{
get
{{
object obj = viewState
Return (obj == NULL)? ButtonimageNameeXTENSION: (String) Obj;
}
set
{{
ViewState
}
}
/// <summary>
/// Specify the alignment method when using the picture button.
/// </summary>
[Browsable (True),
description
defaultValue (ImageAlign.baseline),
category ("Picture button")]]
Public ImageAlign ButtonImagealign
{{
get
{{
object obj = viewState ["ButtonImagealign"];
Return (obj == null)? Imagealign.baseline: (ImageAlign) Obj;
}
set {ViewState ["ButtonImagealign"] = value;}
}
#Endregion
#Region paging
/// <summary>
/// Get or set whether to enable URL to pass the pagination information.
/// </summary>
/// <lmarks>
/// Enable the URL paging method to pass the page index that the user wants to access through the URL. Because the paging method does not use the page to send it to itself to send the data,
/// So every data is restored to the initial value or needed to be obtained at each paging. Use the URL paging method does not support the attribute value of dynamic changes to the paging control.
/// Because the new attribute value is temporarily unable to pass the URL to the next page.
/// </remarks>
/// <EXAMPLE> The following examples show how to use the URL paging method of ASPNETPAGER to paged the DataGrid (using the Access database):
/// <code> <! [cdata [cdata [
/// <%@register tagprefix = "webdiyer" namespace = "wuqi.webdiyer" assembly = "aspnetpager"%>
/// <%@Import namespace = "System.data.OLEDB"%>
/// <%@ Import namespace = "System.data"%>
/// <%@ page language = "c#" debug = true%>
/// <html>
/// <head>
/// <Title> WELCOME to webdiyer.com </Title>
/// <script runat = "server">
/// oledbconnection conn;
/// OLEDBCOMMAND CMD;
/// void page_load (Object SRC, EventArgs E) {{
/// conn = new oledbconnection ("provider = microsoft.jet.OLEDB.4.0; data source ="+server.mAppath ("accept/aspnetpager.mdb");
/// if (! Page.ispostback) {
/// cmd = New OLEDBCOMMAND ("SELECT Count (Newsid) From Wqnews", Conn); Conn);
// conn.open ();
/// pager.Recordcount = (int) cmd.executescalal ();
// conn.close ();
/// binddata ();
///}
///}
///
/// void binddata () {{)
/// cmd = New OLEDBCOMMAND ("SELECT Newsid, Heading, Source, Addtime from wqnews order by addtime design, conn); conn); conn); conn); conn); conn); conn); conn); conn); conn); conn); conn); conn); conn);
/// OLEDBDataAdapter Adapter = New OLEDBDataadapter (CMD);
/// dataset ds = new dataset ();
/// adapter.fill (ds, pager.pageSize*(pager.currentpageIndex-), Pager.pageSize, "News"); "News");
/// dg.datasource = ds.tables ["News"];
/// dg.databind ();
///}
///
/// Void Changepage (Object SRC, PageChangedeventargs E) {{
/// pager.currentpageindex = e.newpageindex;
/// binddata ();
///}
///
/// </script>
/// <meta http-equiv = "Content-Language" Content = "ZH-CN">
/// <meta http-equiv = "Content-Type" Content = "Text/HTML; Charset = GB2312">
/// <meta name = "general" content = "editplus">
/// <meta name = "author" content = "webdiyer ([Email Protected])"> ">">
/// </head>
/// <body>
/// <FORM RUNAT = "Server" ID = "FORM1">
/// <h2 align = "center"> aspnetpager paging example </h2>
/// <asp: datagrid id = "dg" runat = "server"
/// cellpadding = "4" align = "center"/>
///
/// <webdiyer: aspnetpager runat = "server" id = "pager"
/// OnPageChanged = "Changepage"
/// horizontalalally = "Center"
///
/// pageSize = "8"
/// showinputbox = "always"
/// submitButtonStyle = "Border: 1px solid #000066; height: 20px; width: 30px"
/// inputBoxStyle = "Border: 1px #0000ff solid; text-align: center"
/// submitButtontext = "Turn to"
/// urlpaging = "true"
/// urlpageINDEXNAME = "Pageindex"/>
/// </form>
/// </body>
/// </html>
///]]> </code>
/// </Example>
[Browsable (True),
category ("paging"),
DefaultValue (FALSE),
Descripting ("Whether to use the URL to pass the pagination information to pages")]
public bool urlpaging
{{
get
{{
Return urlpaging;
}
set
{{
urlpaging = value;
}
}
/// <summary>
/// Obtain or set it when the URL paging method is enabled, and the name of the parameter of the page index to be transmitted in the URL is in the URL.
/// </summary>
/// <lmarks>
/// This attribute allows you to customize the name of the parameter of the page index to pass through the URL transmission page index to avoid repeating with the existing parameter name.
/// <p> The default value of the attribute is "Page", that is, when the URL paging, the URL displayed in the browser address bar is similar to: </p> http://www.webdiyer.com/aspnetpager/ samples/datagrid_url.aspx? Page = 2
/// <p> If the value is changed to "PageIndex", the URL above will become: </p> <p> http://www.webdiyer.com/aspnetpager/samples/dataGrid_url.aspx?pageIndex = 2 </p>
/// </remarks>
[Browsable (True),
defaultValue ("Page"),
category ("paging"),
Descripting ("When the URL paging method is enabled, the name of the parameter of the page index to indicate in the URL")]]
Public String urlpageindexname
{{
get {Return urlpageindexname;}
set {urlpageindexname = value;}
}
/// <summary>
/// Get or set the index of the current display page.
/// </summary>
/// <Remarks> Use this attribute to determine the page currently displayed in the ASPNETPAGER control. The digital index of the currently displayed page will be shown boldly with red fonts. This attribute is also used to control the page displayed by programming.
/// <p> <b> Note: </b> Different from the CurrentPageIndex of the DataGrid control, the CurrentPageIndex property of ASPNETPAGER starts from 1. </p> </remarks>
[Readonly (TRUE),
browsable (false),
Descripting ("Index of the current display page"),
category ("paging"),
defaultValue (1),
DesignerserializationVisibility (DesignerserializationVisibility.Hidden)]
Public int CurrentPageIndex
{{
get
{{
object cpage = viewstate ["currenTpageIndex"];
int pindex = (cpage == null)? 1: (int) cpage;
If (pindex> PageCount && PageCount> 0)
Return pageCount;
else if (pindex <1)
Return 1;
Return pindex;
}
set
{{
int CPAGE = value;
if (CPAGE <1)
cpage = 1;
Else if (CPAGE> This.PageCount)
cpage = this.pageCount;
ViewState ["CurrentPageINDEX"] = cpage;
}
}
/// <summary>
/// Get or set the total number of all records that need to be paged.
/// </summary>
/// <lmarks>
/// When the page is loaded for the first time, it should be given the attribute to all the total number of paging records in the data table returned from the storage procedure or SQL statement. The ASPNETPAGER will put it in the ViewState saved and on the page on the page The value is obtained from ViewState when returning, so it avoids access to the database every time the pagination is avoided. ASPNETPAGER calculates the total number of pages required by all data based on the total number of data to be paged and the <see Cref = "PageSize"/> attributes to the paging, that is, the value of <see Cref = "PageCount"/>.
/// </remarks>
/// <EXAMPLE>
/// The example below shows how the total number of records returned from the SQL statement is assigned to the attribute:
/// <p>
/// <code> <! [cdata [cdata [
/// <html>
/// <head>
/// <Title> WELCOME to webdiyer.com </Title>
/// <script runat = "server">
/// sqlconnection conn;
/// sqlcommand cmd;
/// void page_load (Object SRC, EventArgs E)
/// {
// conn = new sqlconnection (configurationSettings.appsettings ["connstr"];
/// if (! Page.ispostback)
/// {
/// cmd = new sqlcommand ("select count (id) from news", conn); conn);
// conn.open ();
/// pager.Recordcount = (int) cmd.executescalal ();
// conn.close ();
/// binddata ();
///}
///}
///
/// void binddata ()
/// {
/// cmd = new sqlcommand ("getpagednews", conn);
/// cmd.commandtype = CommandType.storedProceDure;
/// cmd.parameters.add ("@posgeindex", pager.currenTPageIndex);
/// cmd.parameters.add ("@PageSize", pager.pageSize);
// conn.open ();
/// datagrid1.dataSource = cmd.executeReader ();
/// datagrid1.dataBind ();
// conn.close ();
///}
/// Void Changepage (Object SRC, PageChangedeventargs E)
/// {
/// pager.currentpageindex = e.newpageindex;
/// binddata ();
///}
/// </script>
/// <meta http-equiv = "Content-Language" Content = "ZH-CN">
/// <meta http-equiv = "Content-Type" Content = "Text/HTML; Charset = GB2312">
/// <meta name = "general" content = "editplus">
/// <meta name = "author" content = "webdiyer ([Email Protected])"> ">">
/// </head>
/// <body>
/// <FORM RUNAT = "Server" ID = "FORM1">
/// <asp: datagrid id = "datagrid1" runat = "server"/>
///
/// <webdiyer: aspnetpager id = "pager" runat = "server"
/// pageSize = "8"
///numericbuttoncount = "8"
/// showcustominFosection = "Before"
/// showinputbox = "always"
/// cssclass = "MyPager"
/// horizontalalally = "Center"
/// OnPageChanged = "Changepage"/>
///
/// </form>
/// </body>
/// </html>
///]]>
/// </code> </p>
/// <p> The storage procedure code used in this example is as follows: </p>
/// <code> <! [cdata [cdata [
/// Create Procedure getpagednews
/// (@pageSize int,
@pageindex int)
/// as
/// set nocount on
/// DecLARE @INDEXTABLE TABL
/// Declare @pageLowerBound int
/// DecLARE @Pageupperbound int
/// set @Pagelowerbound = (@Pageindex-)*@PageSize
/// set @[Email Protected] [Email Protected]
/// set rowcount @Pageupperbound
/// Insert Into @indextable (NID) SELECT Id FROM News Order by Addtime Desc
/// select o.id, o.title, o.source, o.addtime from news
/// and t.id> @Pagelowerbound and t.id <[email protrly] order by t.id
/// set nocount off
/// GO
///]]>
/// </code>
/// </Example>
[Browsable (FALSE),
Descripting ("The total number of all records to be paged, the value must be set when the program is running, and the default value is 225 is the reference value supported by the design when designing.
Category ("Data"),
DefaultValue (225)]
Public int RecordCount
{{
get
{{
object obj = viewState ["RecordCount"];
Return (obj == null)? 0: (int) obj;
}
set {ViewState ["RecordCount"] = value;}
}
/// <summary>
/// Get the total number of pages that are not displayed after the current page.
/// </summary>
[Browsable (FALSE),
DesignerserializationVisibility (DesignerserializationVisibility.Hidden)]
Public int PageSremain
{{
get
{{
Return PageCount-CurrenTPageINDEX;
}
}
/// <summary>
/// Get or set the number of items displayed per page.
/// </summary>
/// <lmarks>
/// This value acquisition or setting data presents the number of data items in the data table at a time, aspnetpager calculates the total number of pages required for all data based on the value and <see Cref = "RecordCount"/>. The value of <see Cref = "PageCount"/>. </remarks>
/// <EXAMPLE> The following examples are set to set <see Cref = "ASPNETPAGER"/> to allow 8 pieces of data per page:
/// <code>
/// <! [cdata [cdata [
/// ...
/// <webdiyer: aspnetpager id = "Pager" runat = "Server" PageSize = 8 onPageChanged = "Changepage"/>
/// ...
///]]> </code> </example>
[Browsable (True),
description ("Number of records displayed per page"),
category ("paging"),
defaultValue (10)]
Public int PageSize
{{
get
{{
object obj = viewState ["pagesize"];
Return (obj == null)? 10: (int) obj;
}
set
{{
ViewState ["PageSize"] = Value;
}
}
/// <summary>
/// Get the number of remaining records that have not been displayed after the current page.
/// </summary>
[Browsable (FALSE),
DesignerserializationVisibility (DesignerserializationVisibility.Hidden)]
public int Recordsremain
{{
get
{{
if (CurrentPageINEX <PageCount)
Return RecordCount- (CurrentPageINDEX*PageSize);
Return 0;}
}
/// <summary>
/// Get all the total pages required for all the records to be paged.
/// </summary>
[Browsable (FALSE),
DesignerserializationVisibility (DesignerserializationVisibility.Hidden)]
Public int PageCount
{{
Get {Return (int) math.ceiling (double) recredCount/(dough);}
}
#Endregion
#Region textbox and submit Button
/// <summary>
/// Get or set the display method of the page index box.
/// </summary>
/// <lmarks>
/// 页索引文件框允许用户手式输入要访问的页的索引,当页数非常多时,显示页索引文本框非常方便用户跳转到指定的页,默认情况下,该文本框只有在总页数大于或等于<see cref="showboxthreshold"/> 的值时才显示,否则不显示,要想该文本框任何时候都显示,请将其值设为always,若希望任何时候都不显示,则应设为never。
///</remarks>
[browsable(true),
description("指定页索引文本框的显示方式"),
category("文本框及提交按钮"),
defaultvalue(showinputbox.auto)]
public showinputbox showinputbox
{{
get
{{
object obj=viewstate["showinputbox"];
return (obj==null)?showinputbox.auto:(showinputbox)obj;
}
set{viewstate["showinputbox"]=value;}
}
/// <summary>
/// 获取或设置应用于页索引输入文本框的css类名。
/// </summary>
[browsable(true),
category("文本框及提交按钮"),
defaultvalue(null),
description("应用于页索引输入文本框的css类名")]
public string inputboxclass
{{
get
{{
return (string)viewstate["inputboxclass"];
}
set
{{
if(value.trim().length>0)
viewstate["inputboxclass"]=value;
}
}
/// <summary>
/// 获取或设置页索引输入文本框的css样式文本。
/// </summary>
[browsable(true),
category("文本框及提交按钮"),
defaultvalue(null),
description("应用于页索引输入文本框的css样式文本")]
public string inputboxstyle
{{
get
{{
return (string)viewstate["inputboxstyle"];
}
set
{{
if(value.trim().length>0)
viewstate["inputboxstyle"]=value;
}
}
/// <summary>
/// 获取或设置页索引页索引输入文本框前的文本字符串值。
/// </summary>
[browsable(true),
category("文本框及提交按钮"),
defaultvalue(null),
description("页索引输入文本框前的文本内容字符串")]
public string textbeforeinputbox
{{
get
{{
return (string)viewstate["textbeforeinputbox"];
}
set
{{
viewstate["textbeforeinputbox"]=value;
}
}
/// <summary>
/// 获取或设置页索引文本输入框后的文本内容字符串值。
/// </summary>
[browsable(true),
defaultvalue(null),
category("文本框及提交按钮"),
description("页索引输入文本框后的文本内容字符串")]
public string textafterinputbox
{{
get
{{
return (string)viewstate["textafterinputbox"];
}
set
{{
viewstate["textafterinputbox"]=value;
}
}
/// <summary>
/// 获取或设置提交按钮上的文本。
/// </summary>
[browsable(true),
category("文本框及提交按钮"),
defaultvalue("go"),
description("提交按钮上的文本")]
public string submitbuttontext
{{
get
{{
object obj=viewstate["submitbuttontext"];
return (obj==null)?"go":(string)obj;
}
set
{{
if(value.trim().length>0)
viewstate["submitbuttontext"]=value;
}
}
/// <summary>
/// 获取或设置应用于提交按钮的css类名。
/// </summary>
[browsable(true),
category("文本框及提交按钮"),
defaultvalue(null),
description("应用于提交按钮的css类名")]
public string submitbuttonclass
{{
get
{{
return (string)viewstate["submitbuttonclass"];
}
set
{{
viewstate["submitbuttonclass"]=value;
}
}
/// <summary>
/// 获取或设置应用于提交按钮的css样式。
/// </summary>
[browsable(true),
category("文本框及提交按钮"),
defaultvalue(null),
description("应用于提交按钮的css样式")]
public string submitbuttonstyle
{{
get
{{
return (string)viewstate["submitbuttonstyle"];
}
set
{{
viewstate["submitbuttonstyle"]=value;
}
}
/// <summary>
/// 获取或设置自动显示页索引输入文本框的最低起始页数。
/// </summary>
/// <remarks>
/// 当<see cref="showinputbox"/> 设为auto(默认)并且要分页的数据的总页数达到该值时会自动显示页索引输入文本框,默认值为30。该选项当<see cref="showinputbox"/> 设为never或always时没有任何作用。
/// </remarks>
[browsable(true),
description("指定当showinputbox设为showinputbox.auto时,当总页数达到多少时才显示页索引输入文本框"),
category("文本框及提交按钮"),
defaultvalue(30)]
public int showboxthreshold
{{
get
{{
object obj=viewstate["showboxthreshold"];
return (obj==null)?30:(int)obj;
}
set{viewstate["showboxthreshold"]=value;}
}
#endregion
#region custominfosection
/// <summary>
/// 获取或设置显示用户自定义信息区的方式。
/// </summary>
/// <remarks>
/// 该属性值设为left或right时会在分页导航元素左边或右边划出一个专门的区域来显示有关用户自定义信息,设为never时不显示。
/// </remarks>
[browsable(true),
description("显示当前页和总页数信息,默认值为不显示,值为showcustominfosection.left时将显示在页索引前,为showcustominfosection.right时将显示在页索引后"),
defaultvalue(showcustominfosection.never),
category("自定义信息区")]
public showcustominfosection showcustominfosection
{{
get
{{
object obj=viewstate["showcustominfosection"];
return (obj==null)?showcustominfosection.never:(showcustominfosection)obj;
}
set{viewstate["showcustominfosection"]=value;}
}
/// <summary>
/// 获取或设置用户自定义信息区文本的对齐方式。
/// </summary>
[browsable(true),
category("自定义信息区"),
defaultvalue(horizontalalign.left),
description("用户自定义信息区文本的对齐方式")]
public horizontalalign custominfotextalign
{{
get
{{
object obj=viewstate["custominfotextalign"];
return (obj==null)?horizontalalign.left:(horizontalalign)obj;
}
set
{{
viewstate["custominfotextalign"]=value;
}
}
/// <summary>
/// 获取或设置用户自定义信息区的宽度。
/// </summary>
[browsable(true),
category("自定义信息区"),
defaultvalue(typeof(unit),"40%"),
description("用户自定义信息区的宽度")]
public unit custominfosectionwidth
{{
get
{{
object obj=viewstate["custominfosectionwidth"];
return (obj==null)?unit.percentage(40):(unit)obj;
}
set
{{
viewstate["custominfosectionwidth"]=value;
}
}
/// <summary>
/// 获取或设置应用于用户自定义信息区的级联样式表类名。
/// </summary>
[browsable(true),
category("自定义信息区"),
defaultvalue(null),
description("应用于用户自定义信息区的级联样式表类名")]
public string custominfoclass
{{
get
{{
object obj=viewstate["custominfoclass"];
return (obj==null)?cssclass:(string)obj;
}
set
{{
viewstate["custominfoclass"]=value;
}
}
/// <summary>
/// 获取或设置应用于用户自定义信息区的css样式文本。
/// </summary>
/// <value>字符串值,要应用于用户自定义信息区的css样式文本。</value>
[browsable(true),
category("自定义信息区"),
defaultvalue(null),
description("应用于用户自定义信息区的css样式文本")]
public string custominfostyle
{{
get
{{
object obj=viewstate["custominfostyle"];
return (obj==null)?getstylestring():(string)obj;
}
set
{{
viewstate["custominfostyle"]=value;
}
}
/// <summary>
/// 获取或设置在显示在用户自定义信息区的用户自定义文本。
/// </summary>
[browsable(true),
category("自定义信息区"),
defaultvalue(null),
description("要显示在用户自定义信息区的用户自定义信息文本")]
public string custominfotext
{{
get
{{
return (string)viewstate["custominfotext"];
}
set
{{
viewstate["custominfotext"]=value;
}
}
#endregion
#region others
/// <summary>
/// 获取或设置一个值,该值指定是否总是显示aspnetpager分页按件,即使要分页的数据只有一页。
/// </summary>
/// <remarks>
/// 默认情况下,当要分页的数据小于两页时,aspnetpager不会在页面上显示任何内容,将此属性值设为true时,即使总页数只有一页,aspnetpager也将显示分页导航element.
/// </remarks>
[browsable(true),
category("behavior"),
defaultvalue(false),
description("总是显示分页控件,即使要分页的数据只要一页")]
public bool alwaysshow
{{
get
{{
object obj=viewstate["alwaysshow"];
return (obj==null)?false:(bool)obj;
}
set
{{
viewstate["alwaysshow"]=value;
}
}
/// <summary>
/// 获取或设置由aspnetpager 服务器控件在客户端呈现的级联样式表(css) 类。
/// </summary>
[browsable(true),
description("应用于控件的css类名"),
category("appearance"),
defaultvalue(null)]
public override string cssclass
{{
get{return base.cssclass;}
set
{{
base.cssclass=value;
cssclassname=value;
}
}
/// <summary>
/// 获取或设置一个值,该值指示aspnetpager 服务器控件是否向发出请求的客户端保持自己的视图状态,该属性经重写后不允许设为false。
/// </summary>
/// <remarks><see cref="aspnetpager"/> 服务器控件将一些重要的分页信息保存在viewstate中,当使用url分页方式时,虽然视图状态在分页过程中没有任何作用,但若当前页需要回发,则必须启用视图状态以便分页控件能在页面回发后获取回发前的分页状态;当通过页面回发(postback)的方式来分页时,要使aspnetpager正常工作,必须启用视图状态Essence
/// <p><note>该属性并不能禁止用户用<![cdata[<%@page enableviewstate=false%> ]]>页指令来禁用整个页面的视图状态,当使用此指令并且设置aspnetpager通过页面回发来分页时,aspnetpager因为无法获取保存的信息而不能正常工作。</note></p></remarks>
[browsable(false),
description("是否启用控件的视图状态,该属性的值必须为true,不允许用户设置。"),
defaultvalue(true),
category("behavior")]
public override bool enableviewstate
{{
get
{{
return base.enableviewstate;
}
set
{{
base.enableviewstate=true;
}
}
/// <summary>
/// 获取或设置当用户输入的页索引超出范围(大于最大页索引或小于最小页索引)时在客户端显示的错误信息。
/// </summary>
[browsable(true),
description("当用户输入的页索引超出范围(大于最大页索引或小于最小页索引)时在客户端显示的错误信息。"),
defaultvalue("页数超出范围!"),
category("data")]
public string pageindexoutofrangeerrorstring
{{
get
{{
object obj=viewstate["pageindexoutofrangeerrorstring"];
return (obj==null)?"页数超出范围!":(string)obj;
}
set
{{
viewstate["pageindexoutofrangeerrorstring"]=value;
}
}
/// <summary>
/// 获取或设置当用户输入无效的页索引(负值或非数字)时在客户端显示的错误信息。
/// </summary>
[browsable(true),
description("当用户输入无效的页索引(负值或非数字)时在客户端显示的错误信息。"),
defaultvalue("页索引无效!"),
category("data")]
public string invalidpageindexerrorstring
{{
get
{
object obj=viewstate["invalidpageindexerrorstring"];
return (obj==null)?"页索引无效!":(string)obj;
}
set
{
viewstate["invalidpageindexerrorstring"]=value;
}
}
#endregion
#endregion
#region control rendering logic
/// <summary>
/// 重写<see cref="system.web.ui.control.onload"/> 方法。
/// </summary>
/// <param name="e">包含事件数据的<see cref="eventargs"/> 对象。</param>
protected override void onload(eventargs e)
{
if(urlpaging)
{
currenturl=page.request.path;
urlparams=page.request.querystring;
string pageindex=page.request.querystring[urlpageindexname];
int index=1;
try
{
index=int.parse(pageindex);
}
catch{}
onpagechanged(new pagechangedeventargs(index));
}
else
{
inputpageindex=page.request.form[this.uniqueid+"_input"];
}
base.onload(e);
}
/// <summary>
/// 重写<see cref="system.web.ui.control.onprerender"/>方法。
/// </summary>
/// <param name="e">包含事件数据的<see cref="eventargs"/> 对象。</param>
protected override void onprerender(eventargs e)
{
if(pagecount>1)
{
string checkscript="<script language="javascript">function docheck(el){var r=new regexp("^s*(d+)s*$");if(r.test(el.value)){if(regexp.$1<1||regexp.$1>"+pagecount.tostring()+"){alert(""+pageindexoutofrangeerrorstring+"");document.all['"+this.uniqueid+"_input'].select();return false;}return true;}alert(""+invalidpageindexerrorstring+"");document.all['"+this.uniqueid+"_input'].select();return false;}</script>";
if((showinputbox==showinputbox.always)||(showinputbox==showinputbox.auto&&pagecount>=showboxthreshold))
{
if(!page.isclientscriptblockregistered("checkinput"))
page.registerclientscriptblock("checkinput",checkscript);
string script="<script language="javascript" > <!-- nfunction buildurlstring(key,value){ var _key=key.tolowercase(); var prms=location.search; if(prms.length==0) return location.pathname+"?"+_key+"="+value; var params=prms.substring(1).split("&"); var newparam=""; var found=false; for(i=0;i<params.length;i++){ if(params[i].split("=")[0].tolowercase()==_key){ params[i]=_key+"="+value; found=true; break; } } if(found) return location.pathname+"?"+params.join("&"); else return location+"&"+_key+"="+value; }n//--> </script>";
if(!page.isclientscriptblockregistered("buildurlscript"))
page.registerclientscriptblock("buildurlscript",script);
}
}
base.onprerender(e);
}
/// <summary>
/// 重写<see cref="system.web.ui.webcontrols.webcontrol.addattributestorender"/> 方法,将需要呈现的html 属性和样式添加到指定的<see cref="system.web.ui.htmltextwriter"/> 中
/// </summary>
/// <param name="writer"></param>
protected override void addattributestorender(htmltextwriter writer)
{
if(this.page!=null)
this.page.verifyrenderinginserverform(this);
base.addattributestorender(writer);
}
///<summary>
///重写<see cref="system.web.ui.webcontrols.webcontrol.renderbegintag"/> 方法,将<see cref="aspnetpager"/> 控件的html 开始标记输出到指定的<see cref="system.web.ui.htmltextwriter"/> 编写器中。
///</summary>
///<param name="writer"><see cref="system.web.ui.htmltextwriter"/>,表示要在客户端呈现html 内容的输出流。</param>
public override void renderbegintag(htmltextwriter writer)
{
bool showpager=(pagecount>1||(pagecount<=1&&alwaysshow));
writer.writeline();
writer.write("<!------------------------------ ");
writer.write("aspnetpager v4.3 start");
writer.writeline(" ------------------------------>");
writer.write("<!-------------------- ");
writer.write("copyright:2003 webdiyer(www.webdiyer.com)");
writer.write(" ---------------------");
writer.writeline(">");
base.renderbegintag(writer);
if(!showpager)
{
writer.write("<!-----因为总页数只有一页,并且alwaysshow属性设为false,aspnetpager不显示任何内容,若要在总页数只有一页的情况下显示aspnetpager,请将alwaysshow属性设为true!");
writer.write("----->");
}
if((showcustominfosection==showcustominfosection.left||showcustominfosection==showcustominfosection.right)&&showpager)
{
writer.addattribute(htmltextwriterattribute.width,"100%");
writer.addattribute(htmltextwriterattribute.style,getstylestring());
if(height!=unit.empty)
writer.addstyleattribute(htmltextwriterstyle.height,height.tostring());
writer.addattribute(htmltextwriterattribute.border,"0");
writer.addattribute(htmltextwriterattribute.cellpadding,"0");
writer.addattribute(htmltextwriterattribute.cellspacing,"0");
writer.renderbegintag(htmltextwritertag.table);
writer.renderbegintag(htmltextwritertag.tr);
writecellattributes(writer,true);
writer.renderbegintag(htmltextwritertag.td);
}
}
///<summary>
///重写<see cref="system.web.ui.webcontrols.webcontrol.renderendtag"/> 方法,将<see cref="aspnetpager"/> 控件的html 结束标记输出到指定的<see cref="system.web.ui.htmltextwriter"/> 编写器中。
///</summary>
///<param name="writer"><see cref="system.web.ui.htmltextwriter"/>,表示要在客户端呈现html 内容的输出流。</param>
public override void renderendtag(htmltextwriter writer)
{
if((showcustominfosection==showcustominfosection.left||showcustominfosection==showcustominfosection.right)&&(pagecount>1||(pagecount<=1&&alwaysshow)))
{
writer.renderendtag();
writer.renderendtag();
writer.renderendtag();
}
base.renderendtag(writer);
writer.writeline();
writer.write("<!------------------------------- ");
writer.write("aspnetpager v4.3 end");
writer.write(" --------------------------------");
writer.writeline(">");
writer.writeline();
}
/// <summary>
/// 重写<see cref="system.web.ui.webcontrols.webcontrol.rendercontents"/> 方法,将控件的内容呈现到指定<see cref="system.web.ui.htmltextwriter"/> 的编写In the device.
/// </summary>
/// <param name="writer"><see cref="system.web.ui.htmltextwriter"/>,表示要在客户端呈现html 内容的输出流。</param>
protected override void rendercontents(htmltextwriter writer)
{
if(pagecount<=1&&!alwaysshow)
Return;
if(showcustominfosection==showcustominfosection.left)
{
writer.write(custominfotext);
writer.renderendtag();
writecellattributes(writer,false);
writer.addattribute(htmltextwriterattribute.class,cssclass);
writer.renderbegintag(htmltextwritertag.td);
}
int midpage=(int)((currentpageindex-1)/numericbuttoncount);
int pageoffset=midpage*numericbuttoncount;
int endpage=((pageoffset+numericbuttoncount)>pagecount)?pagecount:(pageoffset+numericbuttoncount);
this.createnavigationbutton(writer,"first");
this.createnavigationbutton(writer,"prev");
if(showpageindex)
{
if(currentpageindex>numericbuttoncount)
createmorebutton(writer,pageoffset);
for(int i=pageoffset+1;i<=endpage;i++)
{
createnumericbutton(writer,i);
}
if(pagecount>numericbuttoncount&&endpage<pagecount)
createmorebutton(writer,endpage+1);
}
this.createnavigationbutton(writer,"next");
this.createnavigationbutton(writer,"last");
if((showinputbox==showinputbox.always)||(showinputbox==showinputbox.auto&&pagecount>=showboxthreshold))
{
writer.write(" ");
if(textbeforeinputbox!=null)
writer.write(textbeforeinputbox);
writer.addattribute(htmltextwriterattribute.type,"text");
writer.addstyleattribute(htmltextwriterstyle.width,"30px");
writer.addattribute(htmltextwriterattribute.value,currentpageindex.tostring());
if(inputboxstyle!=null&&inputboxstyle.trim().length>0)
writer.addattribute(htmltextwriterattribute.style,inputboxstyle);
if(inputboxclass!=null&&inputboxclass.trim().length>0)
writer.addattribute(htmltextwriterattribute.class,inputboxclass);
if(pagecount<=1&&alwaysshow)
writer.addattribute(htmltextwriterattribute.readonly,"true");
writer.addattribute(htmltextwriterattribute.name,this.uniqueid+"_input");
string scriptref="docheck(document.all['"+this.uniqueid+"_input'])";
string postref="if(event.keycode==13){if("+scriptref+")__dopostback('"+this.uniqueid+"',document.all['"+this.uniqueid+"_input'].value);else{event.returnvalue=false;}}";
string keydownscript="if(event.keycode==13){if("+scriptref+"){even
csover 发表于:2006.07.21 08:46 ::分类: ( asp.net ) ::阅读:(464次) :: 评论(0) :: 引用(0)
2006 年07 月20日, 星期四
一个简单的分页控件
采用datagrid的默任的分页方式分页,后来发现对于大的数据量速度很慢,net进程占用系统资源也很大,后来写了个分页的存储过程,每次取数据都只取当前页的,分页是分好了,但是发现翻页就没那么方便了,于是自己写了个简单的分页控件,代码如下(编译以后直接形成dll就可以用)。
sample code:
using system;
using system.web.ui;
using system.web.ui.webcontrols;
using system.componentmodel;
namespace pageinfocontrol
{
///<summary>
///webcustomecontrol1的摘要说明
///</summary>
[defaultproperty('totalrecord'),toolboxdata('<{0}:pageinfo runat=server></{0}:pageinfo>')]
public class pageinfo:system.web.ui.webcontrols.webcontrol,ipostbackeventhandler
{
#region construct method
///<summary>
///构造函数
///</summary>
public pageinfo():base(htmltextwritertag.div)
{
}
#endregion
#region variables and constants
public event eventhandler changepageclick;
private string _barbackgroudcolor='#f1f1f1';
private string _barlinkcolor='navy';
private string _barcurrentcolor='#eeeeee';
private int _totalrecord=0;
private int _totalpage=0;
private int _currentpageindex=1;
private int _itemsize=10;
#endregion
#region properties
[description('分页条背景色'),bindable(true),category('appearance'),defaultvalue('#f1f1f1')]
public string barbackgroundcolor
{
get{return _barbackgroundcolor;}
set{_barbackgroundcolor=value;}
}
[description('分页条带链接数字颜色'),bindable(true),category('appearance'),defaultvalue('navy')]
public string barlinkcolor
{
get{return _barlinkcolor;}
set{_barlinkcolor=value;}
}[description('分页条当前页数字颜色'),bindable(true),category('appearance'),defaultvalue('#eeeeee')]
public string barcurrentcolor
{
get{return _barcurrentcolor;}
set{_barcurrentcolor=value;}
} [description('总记录数'),bindable(false),category('behavior'),defaultvalue(0)]
public int totalrecord
{
get{return _totalrecord;}
set
{
foreach(char c in system.convert.tostring(value))
{
if(!char.isnumber(c)
{
_totalrecord=0;
Break;
}
_totalrecord=value;
}
} [description('每页显示记录数'),bindable(true),category('behavior'),defaultvalue(0)]
public int pagesize
{
get{return _pagesize;}
set
{
foreach(char c in system.convert.tostring(value))
{
if(!char.isnumber(c))
{
_pagesize=0;
Break;
}
}
_pagesize=value;
}
}[description('总页数'),bindable(true),category('behavior'),defaultvalue(0)]
public int totalpage
{
get{return _totalpage;}
}[description('数字规格'),bindable(true),category('behavior'),defaultvalue(10)]
public int itemsize
{
get{return _itemsize;}
set
{
foreach(char c in system.convert.tostring(value))
{
if(!char.isnumber(c))
{
_itemsize=10;
Break;
}
}
_itemsize=value;
}
}[description('当前页值'),bindable(true),category('behavior'),defaultvalue(1)]
public int currentpageindex
{
get{return _currentpageindex;}
set{_currentpageindex=value;}
}
#endregion
//定义div的样式
protected override void addattributestorender(htmltextwriter writer)
{
writer.addstyleattribute('white-space','nowrap');
writer.addstyleattribute('padding-top','2px');
writer.addstyleattribute('padding-bottom',2px');
writer.addstyleattribute('width',width.tostring());
writer.addstyleattribute('height',height.tostring());
base.addattributestorender(writer);
}
protected virtual void onpagechangeclick(eventargs e)
{
if(changepageclick!=null)
{
changepageclick(this,e);
}
} public void raisepostbackevent(string eventargument)
{
int pageindex=int.parse(eventargument);
this._currentpageindex=pageindex;
onpagechangeclick(new eventargs());
}
///<summary>
///将此控件呈现给指定的输出参数
///</summary>
///<param name='output'>要写出到的html编写器</param>
protected override void rendercontents(htmltextwriter output)
{this._totalpage=((this.totalrecord/pagesize)*this.pagesize==this.totalrecord)?(this.totalrecord/this.pagesize):((this.totalrecord/this.pagesize)+1);
int beginrecord=(this.currentpageindex-1)*this.pagesize+1;
int endrecord=this.currentpageindex*this.pagesize;
string pageinfo='[共<font color=#cc0000>'+this.totalpage.tostring()+'</font>页/当前第<font color=#cc0000>'+this.currentpageindex.tostring()+'</font>页共<font color=#cc0000>'+totalrecord.tostring()+'</font>条记录,当前记录数<font color=#cc0000>'+begingrecord.tostring()+'</font>到<font color=#cc0000>'+endrecord.tostring()+'</font>]';
string pageliststr='';
string pageindexcolor='#0000c0';
int singlenumber=this.totalpage-(totalpage/itemsize)*itemsize; //得到分页后的尾数(比如:总共58页,按10页规格显示,则尾数为8)
int intpageformax=(this.currentpageindex-1)/itemsize;
int minint=(1+itemsize*intpageformax);
int maxint=((intpageformax+1)*itemsize)>totalpage?totalpage:((intpageformax+1)*itemsize);
if(this.totalrecord==0||this.totalpage==0)
{
pageliststr='<font color='+pageindexcolor+'>0</font>';
pageliststr=pageliststr+'[共<font color=#cc0000>0</font>页/当前第<font color=#cc0000>0</font>页共<font color=#cc0000>0</font>条记录,当前记录数<font color=#cc0000>0</font>到<font color=#cc0000>0</font>]';
output.write(pageliststr);
}
else
{
if(this.totalpage<=this.itemsize)
{
for(int i=1;i<=totalpage;i++)
{
pageindexcolor=currentpageindex==i?'#cc0000':'#0000c0';
if(currentpageindex==i)
pageliststr=pageliststr+'<a title='当前为第['+i+']页' href='#' id=''+this.uniqueid+''><font color='+pageindexcolor+'>'+i.tostring()+'</font></a>';
else
pageliststr=pageliststr+'<a title='点击转到第['+i+']页' id=''+this.uniqueid+'' href=' javascript:'+page.getpostbackeventreference(this,i.tostring())+''><font color='+pageindexcolor+'>'+i.tostring()+'</font></a>';
}
pageliststr=pageliststr==''?'<font color='+pageindexcolor+'>0</font>':pageliststr;
pageliststr=pageliststr+''+pageinfo;
output.write(pageliststr);
}
else
{
for(int i=minint;i<=maxint;i++)
{
pageindexcolor=currentpageindex==i?'#cc0000':'#0000c0';
if(currentpageindex==i)
pageliststr=pageliststr+'<a title='当前为第['+i+']页' href='#' id=''+this.uniqueid+''><font color='+pageindexcolor+'>'+i.tostring()+'</font></a>';
else
pageliststr=pageliststr+'<a title='点击转到第['+i+']页' id=''+this.uniqueid+'' href=' javascript:'+page.getpostbackeventreference(this,i.tostring())+''><font color='+pageindexcolor+'>'+i.tostring()+'</font></a>';
}
//当当前页数小于itemsize且总的页数大于itemsize时
if(currentpageindex<=itemsize && totalpage>itemsize)
{
pageliststr=pageliststr+'<a id=''+this.uniqueid+'' title='点击转到第['+system.convert.tostring(itemsize+1)+']页' href=' javascript:'+page.getpostbackeventreference(this.system.convert.tostring(itemsize+1))+''>>></a>';
//当当前页数大于itemsize,且总的页数减去当前页数大于等于尾数值页数时
if(this.currentpageindex>itemsize && (totalpage-this.currentpageindex)>=singlenumber)
{{
int multiminpageindex=(intpageformax*itemsize);
int multimaxpageindex=((intpageformax+1)*itemsize)+1;
pageliststr='<a id=''+this.uniqueid+'' title='点击转到第['+multiminpageindex+']页' href=' javascrcipt:'+page.getpostbackeventreference(this.multiminpageindex.tostring())+''><<</a>'+pageliststr.trim()+'<a id=''+this.uniqueid+'' title='点击转到第['+multimaxpageindex+']页' href=' javascript:'+page.getpostbackeventreference(this.multimaxpageindex.tostring())+''>>></a>';
}
//当当前页数大于itemsize,且总的页数减去当前页数大于等于尾数值页数时
if(currentpageindex>10 && (totalpage-currentpageindex)<singlenumber)
{
int multiminpageindex=(intpageformax * itemsize);
pageliststr='<a id=''+this.uniqueid+'' title='点击转到第['+multiminpageindex+']页' href=' javascript:'+page.getpostbackeventreference(this,multiminpageindex.tostring ())+''><<</a>'+pageliststr.trim();
}
pageliststr=pageliststr==''?'<font color='+pageindexcolor+'>0</font>':pageliststr;
pageliststr=pageliststr+''+pageinfo;
output.write(pageliststr);
}
}
base.rendercontents(output);
}
}
}
控件中有几个相关的属性,在使用的时候,只需要指定:totalrecord(总记录数)、pagesize(每页的数据记录数)、currentpageindex(当前页面值)、itemsize(分页条显示页面值的Specification)
控件中有个changepageclick事件,可以利用“控件id.currentpageindex”属性来获取当前页面值。
注册会员,创建你的web开发资料库,