//AspNetPager分頁控件源代碼(Version 4.2):
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.ComponentModel.Design;
using System.Collections;
namespace Wuqi.Webdiyer
{
#region AspNetPager Server Control
#region 控件說明及示例
/// <summary>
/// 用於ASP.NET Web應用程序中對數據進行分頁的的服務器控件。
/// </summary>
/// <remarks>不同於DataGrid控件,AspNetPager分頁控件本身並不顯示任何數據,而只顯示頁導航元素,數據在頁面上的顯示方式與該控件無關。該控件可以為DataGrid、DataList、Repeater以及自定義控件進行分頁,配合Sql存儲過程,分頁性能較使用DataGrid分頁有明顯提升,尤其是當數據量大時性能可提升數倍!
/// <p>AspNetPager 2.0 中新增了通過Url來分頁的功能,這使得訪問者可以直接輸入相應的Url來訪問任何頁面,並且搜索引擎也可以直接檢索每個頁面,若使用DataGrid的分頁功能,這是無法實現的。</p>
/// <p>要使用 AspNetPager 分頁控件,必須最少指定它的 <see cref="RecordCount"/> 屬性,指定並編寫 <see cref="PageChanged"/> 事件的處理程序。
/// <see cref="RecordCount"/> 屬性指定要分頁的所有數據的總項數,若未指定該值或該值小於等於 <see cref="PageSize"/> ,則AspNetPager控件不會顯示任何內容。
/// 若未指定並編寫 <see cref="PageChanged"/> 事件處理程序,則當用戶點擊頁導航元素或在頁索引文本框中手式輸入頁索引並提交時AspNetPager不會跳轉到指定的頁。
/// AspNetPager控件的分頁方法和DataGrid基本相同,即在它的 <see cref="PageChanged"/> 事件處理程序中將傳遞事件數據的 <see cref="PageChangedEventArgs"/> 的 <see cref="PageChangedEventArgs.NewPageIndex"/>值賦給 AspNetPager的 <see cref="CurrentPageIndex"/>屬性,然後重新將新的數據與數據顯示控件綁定。 </p></remarks>
/// <example>以下示例說明如何用AspNetPager對DataGrid進行分頁。
/// <code><![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("@pageindex",1);
/// cmd.Parameters.Add("@pagesize",1);
/// cmd.Parameters.Add("@docount",true);
/// conn.Open();
/// pager.RecordCount=(int)cmd.ExecuteScalar();
/// conn.Close();
/// BindData();
/// }
/// }
///
/// void BindData()
/// {
/// cmd=new SqlCommand("GetNews",conn);
/// cmd.CommandType=CommandType.StoredProcedure;
/// cmd.Parameters.Add("@pageindex",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="記錄總數:<font color=\"blue\"><b>"+pager.RecordCount.ToString()+"</b></font>";
/// pager.CustomInfoText+=" 總頁數:<font color=\"blue\"><b>"+pager.PageCount.ToString()+"</b></font>";
/// pager.CustomInfoText+=" 當前頁:<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="Generator" 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"
/// HorizontalAlign="right"
/// OnPageChanged="ChangePage"
/// SubmitButtonText="轉到"
/// NumericButtonTextFormatString="[{0}]"/>
///
/// </form>
/// </body>
///</HTML>
/// ]]>
/// </code>
/// <p>下面是該示例所用的Sql Server存儲過程:</p>
/// <code>
/// <![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 table(id int identity(1,1),nid int)
/// declare @PageLowerBound int
/// declare @PageUpperBound int
/// set @PageLowerBound=(@pageindex-1)*@pagesize
/// set @PageUpperBound=@PageLowerBound+@pagesize
/// 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 O,@indextable t where O.id=t.nid
/// and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id
/// end
/// set nocount off
///GO
/// ]]>
/// </code></example>
#endregion
[DefaultProperty("PageSize")]
[DefaultEvent("PageChanged")]
[ParseChildren(false)]
[PersistChildren(false)]
[Description("專用於ASP.Net Web應用程序的分頁控件")]
[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>
/// 獲取或設置一個值,該值批示當鼠標指針懸停在導航按鈕上時是否顯示工具提示。
/// </summary>
[Browsable(true),
Category("導航按鈕"),
DefaultValue(true),
Description("指定當鼠標停留在導航按鈕上時,是否顯示工具提示")]
public bool ShowNavigationToolTip
{
get
{
object obj=ViewState["ShowNavigationToolTip"];
return (obj==null)?true:(bool)obj;
}
set
{
ViewState["ShowNavigationToolTip"]=value;
}
}
/// <summary>
/// 獲取或設置導航按鈕工具提示文本的格式。
/// </summary>
[Browsable(true),
Category("導航按鈕"),
DefaultValue("轉到第{0}頁"),
Description("頁導航按鈕工具提示文本的格式")]
public string NavigationToolTipTextFormatString
{
get
{
object obj=ViewState["NavigationToolTipTextFormatString"];
return (obj==null)?"轉到第{0}頁":(string)obj;
}
set
{
string tip=value;
if(tip.Trim().Length<1&&tip.IndexOf("{0}")<0)
tip="{0}";
ViewState["NavigationToolTipTextFormatString"]=tip;
}
}
/// <summary>
/// 獲取或設置一個值,該值指示是否將頁索引按鈕用中文數字代替。
/// </summary>
/// <remarks>
/// 將該值設為true並且未使用圖片按鈕時,頁索引按鈕中的數值1、2、3等將會被中文字符一、二、三等代替。
/// </remarks>
[Browsable(true),
Category("導航按鈕"),
DefaultValue(false),
Description("是否將頁索引數值按鈕用中文數字一、二、三等代替")]
public bool ChinesePageIndex
{
get
{
object obj=ViewState["ChinesePageIndex"];
return (obj==null)?false:(bool)obj;
}
set
{
ViewState["ChinesePageIndex"]=value;
}
}
/// <summary>
/// 獲取或設置頁索引數值導航按鈕上文字的顯示格式。
/// </summary>
/// <value>
/// 字符串,指定頁索引數值按鈕上文字的顯示格式,默認值為<see cref="String.Empty"/>,即未設置該屬性。</value>
/// <remarks>
/// 使用NumericButtonTextFormatString屬性指定頁索引數值按鈕的顯示格式,如未設置該值時索引按鈕文本將會是:1 2 3 ...,設置該值將改變索引按鈕文本的顯示格式,
/// 如將該值設為“[{0}]”則索引文本會顯示為:[1] [2] [3] ...,將該值設為“-{0}-”則會使索引文本變為:-1- -2- -3- ...。
/// </remarks>
[Browsable(true),
DefaultValue(""),
Category("導航按鈕"),
Description("頁索引數值按鈕上文字的顯示格式")]
public string NumericButtonTextFormatString
{
get
{
object obj=ViewState["NumericButtonTextFormatString"];
return (obj==null)?String.Empty:(string)obj;
}
set
{
ViewState["NumericButtonTextFormatString"]=value;
}
}
/// <summary>
/// 獲取或設置分頁導航按鈕的類型,即使用文字還是圖片。
/// </summary>
/// <remarks>
/// 要使用圖片按鈕,您需要准備以下圖片:從0到9的十個數值圖片(當ShowPageIndex設為true時),第一頁、上一頁、下一頁、最後一頁及更多頁(...)五個按鈕圖片(當ShowFirstLast及ShowPrevNext都設為true時),
/// 若需要使當前頁索引的數值按鈕不同於別的頁索引數值按鈕,則還需准備當前頁索引的按鈕圖片;
/// 若需要使已禁用的第一頁、上一頁、下一頁及最後一頁按鈕圖片不同於正常的按鈕圖片,則還需准備這四個按鈕在禁用狀態下的圖片;
/// <p><b>圖片文件的命名規則如下:</b></p>
/// <p>從0到9十張數值按鈕圖片必須命名為“數值+ButtonImageNameExtension+ButtonImageExtension”,其中的ButtonImageNameExtension可以不用設置,
/// ButtonImageExtension是圖片文件的後綴名,如 .gif或 .jpg等可以在浏覽器中顯示的任何圖片文件類型。如頁索引“1”的圖片文件可命名為“1.gif”或“1.jpg”,
/// 當您有兩套或更多套圖片文件時,可以通過指定ButtonImageNameExtension屬性值來區分不同套的圖片,如第一套圖片可以不用設ButtonImageNameExtension,則圖片文件名類似於“1.gif”、“2.gif”等等,而第二套圖片則設置ButtonImageNameExtension為“f”,圖片文件名類似於“1f.gif”,“2f.gif”等等。</p>
/// <p>第一頁按鈕的圖片文件名以“first”開頭,上一頁按鈕圖片名以“prev”開頭,下一頁按鈕圖片名以“next”開頭,最後一頁按鈕圖片名以“last”開頭,更多頁按鈕圖片名以“more”開頭,是否使用ButtonImageNameExtension取決於數值按鈕的設置及是否有更多套圖片。</p>
/// </remarks>
/// <example>
/// 以下代碼片段示例如果使用圖片按鈕:
/// <p>
/// <code><![CDATA[
/// <Webdiyer:AspNetPager runat="server"
/// id="pager1"
/// OnPageChanged="ChangePage"
/// PagingButtonType="image"
/// ImagePath="images"
/// ButtonImageNameExtension="n"
/// DisabledButtonImageNameExtension="g"
/// ButtonImageExtension="gif"
/// CpiButtonImageNameExtension="r"
/// PagingButtonSpacing=5/>
/// ]]>
/// </code>
/// </p>
/// </example>
[Browsable(true),
DefaultValue(PagingButtonType.Text),
Category("導航按鈕"),
Description("分頁導航按鈕的類型,是使用文字還是圖片")]
public PagingButtonType PagingButtonType
{
get
{
object obj=ViewState["PagingButtonType"];
return (obj==null)?PagingButtonType.Text:(PagingButtonType)obj;
}
set
{
ViewState["PagingButtonType"]=value;
}
}
/// <summary>
/// 獲取或設置頁導航數值按鈕的類型,該值僅當PagingButtonType設為Image時才有效。
/// </summary>
/// <remarks>
/// 當您將PagingButtonType設為Image當又不想讓頁索引數值按鈕使用圖片時,可以將該值設為Text,這會使頁索引數據按鈕使用文本而不是圖片按鈕。
/// </remarks>
[Browsable(true),
DefaultValue(PagingButtonType.Text),
Category("導航按鈕"),
Description("頁導航數值按鈕的類型")]
public PagingButtonType NumericButtonType
{
get
{
object obj=ViewState["NumericButtonType"];
return (obj==null)?PagingButtonType:(PagingButtonType)obj;
}
set
{
ViewState["NumericButtonType"]=value;
}
}
/// <summary>
/// 獲取或設置第一頁、上一頁、下一頁和最後一頁按鈕的類型,該值僅當PagingButtonType設為Image時才有效。
/// </summary>
/// <remarks>
/// 當您將PagingButtonType設為Image但又不想讓第一頁、下一頁、下一頁和最後一頁按鈕使用圖片,則可以將該值設為Text,這會使前面的四個按鈕使用文本而不是圖片按鈕。
/// </remarks>
[Browsable(true),
Category("導航按鈕"),
DefaultValue(PagingButtonType.Text),
Description("第一頁、上一頁、下一頁和最後一頁按鈕的類型")]
public PagingButtonType NavigationButtonType
{
get
{
object obj=ViewState["NavigationButtonType"];
return (obj==null)?PagingButtonType:(PagingButtonType)obj;
}
set
{
ViewState["NavigationButtonType"]=value;
}
}
/// <summary>
/// 獲取或設置“更多頁”(...)按鈕的類型,該值僅當PagingButtonType設為Image時才有效。
/// </summary>
/// <remarks>
/// 當您將PagingButtonType設為Image但又不想讓更多頁(...)按鈕使用圖片時,可以將此值設為Text,這會使更多頁按鈕使用文本而不是圖片按鈕。
/// </remarks>
[Browsable(true),
Category("導航按鈕"),
DefaultValue(PagingButtonType.Text),
Description("“更多頁”(...)按鈕的類型")]
public PagingButtonType MoreButtonType
{
get
{
object obj=ViewState["MoreButtonType"];
return (obj==null)?PagingButtonType:(PagingButtonType)obj;
}
set
{
ViewState["MoreButtonType"]=value;
}
}
/// <summary>
/// 獲取或設置分頁導航按鈕之間的間距。
/// </summary>
[Browsable(true),
Category("導航按鈕"),
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>
/// 獲取或設置一個值,該值指示是否在頁導航元素中顯示第一頁和最後一頁按鈕。
/// </summary>
[Browsable(true),
Description("是否在頁導航元素中顯示第一頁和最後一頁按鈕"),
Category("導航按鈕"),
DefaultValue(true)]
public bool ShowFirstLast
{
get
{
object obj=ViewState["ShowFirstLast"];
return (obj==null)?true:(bool)obj;
}
set{ViewState["ShowFirstLast"]=value;}
}
/// <summary>
/// 獲取或設置一個值,該值指示是否在頁導航元素中顯示上一頁和下一頁按鈕。
/// </summary>
[Browsable(true),
Description("是否在頁導航元素中顯示上一頁和下一頁按鈕"),
Category("導航按鈕"),
DefaultValue(true)]
public bool ShowPrevNext
{
get
{
object obj=ViewState["ShowPrevNext"];
return (obj==null)?true:(bool)obj;
}
set{ViewState["ShowPrevNext"]=value;}
}
/// <summary>
/// 獲取或設置一個值,該值指示是否在頁導航元素中顯示頁索引數值按鈕。
/// </summary>
[Browsable(true),
Description("是否在頁導航元素中顯示數值按鈕"),
Category("導航按鈕"),
DefaultValue(true)]
public bool ShowPageIndex
{
get
{
object obj=ViewState["ShowPageIndex"];
return (obj==null)?true:(bool)obj;
}
set{ViewState["ShowPageIndex"]=value;}
}
/// <summary>
/// 獲取或設置為第一頁按鈕顯示的文本。
/// </summary>
[Browsable(true),
Description("第一頁按鈕上顯示的文本"),
Category("導航按鈕"),
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>
/// 獲取或設置為上一頁按鈕顯示的文本。
/// </summary>
[Browsable(true),
Description("上一頁按鈕上顯示的文本"),
Category("導航按鈕"),
DefaultValue("<font face=\"webdings\">3</font>")]
public string PrevPageText
{
get
{
object obj=ViewState["PrevPageText"];
return (obj==null)?"<font face=\"webdings\">3</font>":(string)obj;
}
set{ViewState["PrevPageText"]=value;}
}
/// <summary>
/// 獲取或設置為下一頁按鈕顯示的文本。
/// </summary>
[Browsable(true),
Description("下一頁按鈕上顯示的文本"),
Category("導航按鈕"),
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>
/// 獲取或設置為最後一頁按鈕顯示的文本。
/// </summary>
[Browsable(true),
Description("最後一頁按鈕上顯示的文本"),
Category("導航按鈕"),
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>
/// 獲取或設置在 <see cref="AspNetPager"/> 控件的頁導航元素中同時顯示的數值按鈕的數目。
/// </summary>
[Browsable(true),
Description("要顯示的頁索引數值按鈕的數目"),
Category("導航按鈕"),
DefaultValue(10)]
public int NumericButtonCount
{
get
{
object obj=ViewState["NumericButtonCount"];
return (obj==null)?10:(int)obj;
}
set{ViewState["NumericButtonCount"]=value;}
}
/// <summary>
/// 獲取或設置一個值,該值指定是否顯示已禁用的按鈕。
/// </summary>
/// <remarks>
/// 該值用來指定是否顯示已禁用的分頁導航按鈕,當當前頁為第一頁時,第一頁和上一頁按鈕將被禁用,當當前頁為最後一頁時,下一頁和最後一頁按鈕將被禁用,被禁用的按鈕沒有鏈接,在按鈕上點擊也不會有任何作用。
/// </remarks>
[Browsable(true),
Category("導航按鈕"),
Description("是否顯示已禁用的按鈕"),
DefaultValue(true)]
public bool ShowDisabledButtons
{
get
{
object obj=ViewState["ShowDisabledButtons"];
return (obj==null)?true:(bool)obj;
}
set
{
ViewState["ShowDisabledButtons"]=value;
}
}
#endregion
#region Image Buttons
/// <summary>
/// 獲取或設置當使用圖片按鈕時,圖片文件的路徑。
/// </summary>
[Browsable(true),
Category("圖片按鈕"),
Description("當使用圖片按鈕時,指定圖片文件的路徑"),
DefaultValue(null)]
public string ImagePath
{
get
{
string imgPath=(string)ViewState["ImagePath"];
if(imgPath!=null)
imgPath=this.ResolveUrl(imgPath);
return imgPath;
}
set
{
string imgPath=value.Trim().Replace("\\","/");
ViewState["ImagePath"]=(imgPath.EndsWith("/"))?imgPath:imgPath+"/";
}
}
/// <summary>
/// 獲取或設置當使用圖片按鈕時,圖片的類型,如gif或jpg,該值即圖片文件的後綴名。
/// </summary>
[Browsable(true),
Category("圖片按鈕"),
DefaultValue(".gif"),
Description("當使用圖片按鈕時,圖片的類型,如gif或jpg,該值即圖片文件的後綴名")]
public string ButtonImageExtension
{
get
{
object obj=ViewState["ButtonImageExtension"];
return (obj==null)?".gif":(string)obj;
}
set
{
string ext=value.Trim();
ViewState["ButtonImageExtension"]=(ext.StartsWith("."))?ext:("."+ext);
}
}
/// <summary>
/// 獲取或設置自定義圖片文件名的後綴字符串,以區分不同類型的按鈕圖片。
/// </summary>
/// <remarks><note>注意:</note>該值不是文件後綴名,而是為區分不同的圖片文件而在圖片名中加入的字符串,如:
/// 當前有兩套按鈕圖片,其中一套中的“1”的圖片名可為“1f.gif”,另一套中的“1”的圖片名可起為“1n.gif”,其中的f和n即為ButtonImageNameExtension。</remarks>
[Browsable(true),
DefaultValue(null),
Category("圖片按鈕"),
Description("自定義圖片文件名的後綴字符串(非文件後綴名),如圖片“1f.gif”的ButtonImageNameExtension即為“f”")]
public string ButtonImageNameExtension
{
get
{
return (string)ViewState["ButtonImageNameExtension"];
}
set
{
ViewState["ButtonImageNameExtension"]=value;
}
}
/// <summary>
/// 獲取或設置當前頁索引按鈕的圖片名後綴。
/// </summary>
/// <remarks>
/// 當 <see cref="PagingButtonType"/> 設為 Image 時,該屬性允許您設置當前頁索引數值按鈕使用的圖片名後綴字符,因此可以使當前頁索引按鈕與其它頁索引按鈕使用不同的圖片,若未設置該值,則默認值為<see cref="ButtonImageNameExtension"/>,即當前頁索引按鈕與其它頁索引按鈕使用相同的圖片。
/// </remarks>
[Browsable(true),
DefaultValue(null),
Category("圖片按鈕"),
Description("當前頁索引按鈕的圖片名後綴字符串")]
public string CpiButtonImageNameExtension
{
get
{
object obj=ViewState["CpiButtonImageNameExtension"];
return (obj==null)?ButtonImageNameExtension:(string)obj;
}
set
{
ViewState["CpiButtonImageNameExtension"]=value;
}
}
/// <summary>
/// 獲取或設置已禁用的頁導航按鈕圖片名後綴字符串。
/// </summary>
/// <remarks>
/// 當 <see cref="PagingButtonType"/> 設為 Image 時, 該值允許您設置已禁用(即沒有鏈接,因而點擊後無反應)的頁導航按鈕(包括第一頁、上一頁、下一頁、最後一頁四個按鈕)的圖片文件名後綴字符串,因此可以使已禁用的頁導航按鈕不同於正常的頁導航按鈕。若未設置該值,則默認值為<see cref="ButtonImageNameExtension"/>,即已禁用的頁導航按鈕與正常的頁導航按鈕使用相同的圖片。
/// </remarks>
[Browsable(true),
DefaultValue(null),
Category("圖片按鈕"),
Description("已禁用的頁導航按鈕的圖片名後綴字符串")]
public string DisabledButtonImageNameExtension
{
get
{
object obj=ViewState["DisabledButtonImageNameExtension"];
return (obj==null)?ButtonImageNameExtension:(string)obj;
}
set
{
ViewState["DisabledButtonImageNameExtension"]=value;
}
}
/// <summary>
/// 指定當使用圖片按鈕時,圖片的對齊方式。
/// </summary>
[Browsable(true),
Description("指定當使用圖片按鈕時,圖片的對齊方式"),
DefaultValue(ImageAlign.Baseline),
Category("圖片按鈕")]
public ImageAlign ButtonImageAlign
{
get
{
object obj=ViewState["ButtonImageAlign"];
return (obj==null)?ImageAlign.Baseline:(ImageAlign)obj;
}
set{ViewState["ButtonImageAlign"]=value;}
}
#endregion
#region Paging
/// <summary>
/// 獲取或設置是否啟用url來傳遞分頁信息。
/// </summary>
/// <remarks>
/// 啟用Url分頁方式是將用戶欲訪問的頁索引通過Url來傳遞,由於該分頁方式不使用頁面向自身回發來傳遞數據,
/// 所以每次分頁時所有的數據都恢復為初始值或需要重新獲取。使用Url分頁方式不支持動態改變分頁控件的屬性值,
/// 因暫時無法將新的屬性值通過Url來傳遞給下一頁。
/// </remarks>
/// <example>以下示例說明如何用AspNetPager的Url分頁方式對DataGrid進行分頁(使用Access數據庫):
/// <code><![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("access/aspnetpager.mdb"));
/// if(!Page.IsPostBack){
/// cmd=new OleDbCommand("select count(newsid) from wqnews",conn);
/// conn.Open();
/// pager.RecordCount=(int)cmd.ExecuteScalar();
/// conn.Close();
/// BindData();
/// }
/// }
///
/// void BindData(){
/// cmd=new OleDbCommand("select newsid,heading,source,addtime from wqnews order by addtime desc",conn);
/// OleDbDataAdapter adapter=new OleDbDataAdapter(cmd);
/// DataSet ds=new DataSet();
/// adapter.Fill(ds,pager.PageSize*(pager.CurrentPageIndex-1),pager.PageSize,"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="Generator" CONTENT="EditPlus">
/// <META NAME="Author" CONTENT="Webdiyer(
[email protected])">
/// </HEAD>
/// <body>
/// <form runat="server" ID="Form1">
/// <h2 align="center">AspNetPager分頁示例</h2>
/// <asp:DataGrid id="dg" runat="server"
/// Width="760" CellPadding="4" Align="center" />
///
/// <Webdiyer:AspNetPager runat="server" id="pager"
/// OnPageChanged="ChangePage"
/// HorizontalAlign="center"
/// style="MARGIN-TOP:10px;FONT-SIZE:16px"
/// PageSize="8"
/// ShowInputBox="always"
/// SubmitButtonStyle="border:1px solid #000066;height:20px;width:30px"
/// InputBoxStyle="border:1px #0000FF solid;text-align:center"
/// SubmitButtonText="轉到"
/// UrlPaging="true"
/// UrlPageIndexName="pageindex" />
/// </form>
/// </body>
///</HTML>
/// ]]></code>
/// </example>
[Browsable(true),
Category("分頁"),
DefaultValue(false),
Description("是否使用url傳遞分頁信息的方式來分頁")]
public bool UrlPaging
{
get
{
return urlPaging;
}
set
{
urlPaging=value;
}
}
/// <summary>
/// 獲取或設置當啟用Url分頁方式時,在url中表示要傳遞的頁索引的參數的名稱。
/// </summary>
/// <remarks>
/// 該屬性允許您自定義通過Url傳遞頁索引時表示要傳遞的頁索引的參數的名稱,以避免與現有的參數名重復。
/// <p>該屬性的默認值是“page”,即通過Url分頁時,顯示在浏覽器地址欄中的Url類似於:</p>http://www.webdiyer.com/aspnetpager/samples/datagrid_url.aspx?page=2
/// <p>如將該值改為“pageindex”,則上面的Url將變為:</p><p>http://www.webdiyer.com/aspnetpager/samples/datagrid_url.aspx?pageindex=2 </p>
/// </remarks>
[Browsable(true),
DefaultValue("page"),
Category("分頁"),
Description("當啟用Url分頁方式時,顯示在url中表示要傳遞的頁索引的參數的名稱")]
public string UrlPageIndexName
{
get{return urlPageIndexName;}
set{urlPageIndexName=value;}
}
/// <summary>
/// 獲取或設置當前顯示頁的索引。
/// </summary>
///<remarks>使用此屬性來確定在 AspNetPager 控件中當前顯示的頁,當前顯示的頁的數字索引將以紅色字體加粗顯示。此屬性還用於以編程的方式控制所顯示的頁。
///<p> <b>注意:</b>不同於DataGrid控件的CurrentPageIndex,AspNetPager的CurrentPageIndex屬性是從1開始的。</p></remarks>
[ReadOnly(true),
Browsable(false),
Description("當前顯示頁的索引"),
Category("分頁"),
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>
/// 獲取或設置需要分頁的所有記錄的總數。
/// </summary>
/// <remarks>
/// 當頁面第一次加載時,應以編程方式將從存儲過程或Sql語句中返回的數據表中所有要分頁的記錄的總數賦予該屬性,AspNetPager會將其保存的ViewState中並在頁面回發時從ViewState中獲取該值,因此避免了每次分頁都要訪問數據庫而影響分頁性能。AspNetPager根據要分頁的所有數據的總項數和 <see cref="PageSize"/> 屬性來計算顯示所有數據需要的總頁數,即 <see cref="PageCount"/>的值。
/// </remarks>
/// <example>
/// 下面的示例顯示如何以編程方式將從Sql語句返回的記錄總數賦給該屬性:
/// <p>
/// <code><![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.Open();
/// pager.RecordCount=(int)cmd.ExecuteScalar();
/// conn.Close();
/// BindData();
/// }
/// }
///
/// void BindData()
/// {
/// cmd=new SqlCommand("GetPagedNews",conn);
/// cmd.CommandType=CommandType.StoredProcedure;
/// cmd.Parameters.Add("@pageindex",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="Generator" 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"
/// HorizontalAlign="center"
/// OnPageChanged="ChangePage" />
///
/// </form>
/// </body>
///</HTML>
/// ]]>
/// </code></p>
/// <p>本示例使用的存儲過程代碼如下:</p>
/// <code><![CDATA[
///CREATE procedure GetPagedNews
/// (@pagesize int,
/// @pageindex int)
/// as
/// set nocount on
/// declare @indextable table(id int identity(1,1),nid int)
/// declare @PageLowerBound int
/// declare @PageUpperBound int
/// set @PageLowerBound=(@pageindex-1)*@pagesize
/// set @PageUpperBound=@PageLowerBound+@pagesize
/// 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 O,@indextable t where O.id=t.nid
/// and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id
/// set nocount off
///GO
/// ]]>
/// </code>
/// </example>
[Browsable(false),
Description("要分頁的所有記錄的總數,該值須在程序運行時設置,默認值為225是為設計時支持而設置的參照值。"),
Category("Data"),
DefaultValue(225)]
public int RecordCount
{
get
{
object obj=ViewState["Recordcount"];
return (obj==null)?0:(int)obj;
}
set{ViewState["Recordcount"]=value;}
}
/// <summary>
/// 獲取當前頁之後未顯示的頁的總數。
/// </summary>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int PagesRemain
{
get
{
return PageCount-CurrentPageIndex;
}
}
/// <summary>
/// 獲取或設置每頁顯示的項數。
/// </summary>
/// <remarks>
/// 該值獲取或設置數據呈現控件每次要顯示數據表中的的數據的項數,AspNetPager根據該值和 <see cref="RecordCount"/> 來計算顯示所有數據需要的總頁數,即 <see cref="PageCount"/>的值。</remarks>
/// <example>以下示例將 <see cref="AspNetPager"/> 設置為允許每頁顯示8條數據:
/// <code>
/// <![CDATA[
/// ...
/// <Webdiyer:AspNetPager id="pager" runat="server" PageSize=8 OnPageChanged="ChangePage"/>
/// ...
/// ]]></code></example>
[Browsable(true),
Description("每頁顯示的記錄數"),
Category("分頁"),
DefaultValue(10)]
public int PageSize
{
get
{
object obj=ViewState["PageSize"];
return (obj==null)?10:(int)obj;
}
set
{
ViewState["PageSize"]=value;
}
}
/// <summary>
/// 獲取在當前頁之後還未顯示的剩余記錄的項數。
/// </summary>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int RecordsRemain
{
get
{
if(CurrentPageIndex<PageCount)
return RecordCount-(CurrentPageIndex*PageSize);
return 0;}
}
/// <summary>
/// 獲取所有要分頁的記錄需要的總頁數。
/// </summary>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int PageCount
{
get{return (int)Math.Ceiling((double)RecordCount/(double)PageSize);}
}
#endregion
#region TextBox and Submit Button
/// <summary>
/// 獲取或設置頁索引文本框的顯示方式。
/// </summary>
/// <remarks>
/// 頁索引文件框允許用戶手式輸入要訪問的頁的索引,當頁數非常多時,顯示頁索引文本框非常方便用戶跳轉到指定的頁,默認情況下,該文本框只有在總頁數大於或等於 <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["InpubBoxClass"];
}
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也將顯示分頁導航元素。
/// </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正常工作,必須啟用視圖狀態。
/// <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;
}
}
#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(\"頁數必須介於1和"+PageCount.ToString()+"之間!\");document.all[\'"+this.UniqueID+"_input\'].select();return false;}return true;}alert(\"輸入的頁索引無效!\");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 loc=window.location.search.substring(1); var params=loc.split(\"&\"); if(params.length<=1||(params.length==2&¶ms[0].toLowerCase()==key)) return location.pathname+\"?\"+key+\"=\"+value; var newparam=\"\"; var flag=false; for(i=0;i<params.length;i++){ if(params[i].split(\"=\")[0].toLowerCase()==key.toLowerCase()){ params[i]=key+\"=\"+value; flag=true; break; } } for(i=0;i<params.length;i++){ newparam+=params[i]+\"&\"; } if(flag) newparam=newparam.substring(0,newparam.length-1); else newparam+=key+\"=\"+value; return location.pathname+\"?\"+newparam; } \n//--> </script>";
if(!Page.IsClientScriptBlockRegistered("BuildUrlScript"))
Page.RegisterClientScriptBlock("BuildUrlScript",script);
}
}
base.OnPreRender(e);
}
///<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.2 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)
{
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderEndTag();
}
base.RenderEndTag(writer);
writer.WriteLine();
writer.Write("<!------------------------------- ");
writer.Write("AspNetPager V4.2 End");
writer.Write(" --------------------------------");
writer.WriteLine(">");
writer.WriteLine();
}
/// <summary>
/// 重寫 <see cref="System.Web.UI.WebControls.WebControl.RenderContents"/> 方法,將控件的內容呈現到指定 <see cref="System.Web.UI.HtmlTextWriter"/> 的編寫器中。
/// </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,inputPageIndex);
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+"){event.returnValue=false;document.all[\'"+this.UniqueID+"\'][1].click();}else{event.returnValue=false;}}";
string clickScript="if("+scriptRef+"){location.href=BuildUrlString(\'"+urlPageIndexName+"\',document.all[\'"+this.UniqueID+"_input\'].value)}";
writer.AddAttribute("onkeydown",(urlPaging==true)?keydownScript:postRef);
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
if(TextAfterInputBox!=null)
writer.Write(TextAfterInputBox);
writer.AddAttribute(HtmlTextWriterAttribute.Type,(urlPaging==true)?"Button":"Submit");
writer.AddAttribute(HtmlTextWriterAttribute.Name,this.UniqueID);
writer.AddAttribute(HtmlTextWriterAttribute.Value,SubmitButtonText);
if(SubmitButtonClass!=null&&SubmitButtonClass.Trim().Length>0)
writer.AddAttribute(HtmlTextWriterAttribute.Class,SubmitButtonClass);
if(SubmitButtonStyle!=null&&SubmitButtonStyle.Trim().Length>0)
writer.AddAttribute(HtmlTextWriterAttribute.Style,SubmitButtonStyle);
if(PageCount<=1&&AlwaysShow)
writer.AddAttribute(HtmlTextWriterAttribute.Disabled,"true");
writer.AddAttribute(HtmlTextWriterAttribute.Onclick,(urlPaging==true)?clickScript:"return "+scriptRef);
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();}
if(ShowCustomInfoSection==ShowCustomInfoSection.Right)
{
writer.RenderEndTag();
WriteCellAttributes(writer,false);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(CustomInfoText);
}
}
#endregion
#region Private Helper Functions
/// <summary>
/// 將基控件的Style轉換為CSS字符串。
/// </summary>
/// <returns></returns>
private string GetStyleString()
{
if(Style.Count>0)
{
string stl=null;
string[] skeys=new string[Style.Count];
Style.Keys.CopyTo(skeys,0);
for(int i=0;i<skeys.Length;i++)
{
stl+=String.Concat(skeys[i],":",Style[skeys[i]],";");
}
return stl;
}
return null;
}
/// <summary>
/// 為用戶自定義信息區和頁導航按鈕區和td添加屬性。
/// </summary>
/// <param name="writer"></param>
/// <param name="leftCell">是否為第一個td</param>
private void WriteCellAttributes(HtmlTextWriter writer,bool leftCell)
{
string customUnit=CustomInfoSectionWidth.ToString();
if(ShowCustomInfoSection==ShowCustomInfoSection.Left&&leftCell||ShowCustomInfoSection==ShowCustomInfoSection.Right&&!leftCell)
{
if(CustomInfoClass!=null&&CustomInfoClass.Trim().Length>0)
writer.AddAttribute(HtmlTextWriterAttribute.Class,CustomInfoClass);
if(CustomInfoStyle!=null&&CustomInfoStyle.Trim().Length>0)
writer.AddAttribute(HtmlTextWriterAttribute.Style,CustomInfoStyle);
writer.AddAttribute(HtmlTextWriterAttribute.Valign,"bottom");
writer.AddStyleAttribute(HtmlTextWriterStyle.Width,customUnit);
writer.AddAttribute(HtmlTextWriterAttribute.Align,CustomInfoTextAlign.ToString().ToLower());
}
else
{
if(CustomInfoSectionWidth.Type==UnitType.Percentage)
{
customUnit=(Unit.Percentage(100-CustomInfoSectionWidth.Value)).ToString();
writer.AddStyleAttribute(HtmlTextWriterStyle.Width,customUnit);
}
writer.AddAttribute(HtmlTextWriterAttribute.Valign,"bottom");
writer.AddAttribute(HtmlTextWriterAttribute.Align,HorizontalAlign.ToString().ToLower());
}
writer.AddAttribute(HtmlTextWriterAttribute.Nowrap,"true");
}
/// <summary>
/// 獲取分頁導航按鈕的超鏈接字符串。
/// </summary>
/// <param name="pageIndex">該分頁按鈕相對應的頁索引。</param>
/// <returns>分頁導航按鈕的超鏈接字符串。</returns>
private string GetHrefString(int pageIndex)
{
if(urlPaging)
{
NameValueCollection col=new NameValueCollection();
col.Add(urlPageIndexName,pageIndex.ToString());
return BuildUrlString(col);
}
return Page.GetPostBackClientHyperlink(this,pageIndex.ToString());
}
/// <summary>
/// 當使用Url分頁方式時,在當前Url上加入分頁參數,若該參數存在,則改變其值。
/// </summary>
/// <param name="col">要加入到新Url中的參數名和值的集合。</param>
/// <returns>分頁導航按鈕的超鏈接字符串,包括分頁參數。</returns>
private string BuildUrlString(NameValueCollection col)
{
int i;
string tempstr="";
if(urlParams==null||urlParams.Count<=0)
{
for(i=0;i<col.Count;i++)
{
tempstr+=String.Concat("&",col.Keys[i],"=",col[i]);
}
return String.Concat(currentUrl,"?",tempstr.Substring(1));
}
NameValueCollection newCol=new NameValueCollection(urlParams);
string[] newColKeys=newCol.AllKeys;
for(i=0;i<newColKeys.Length;i++)
{
newColKeys[i]=newColKeys[i].ToLower();
}
for(i=0;i<col.Count;i++)
{
if(Array.IndexOf(newColKeys,col.Keys[i].ToLower())<0)
newCol.Add(col.Keys[i],col[i]);
else
newCol[col.Keys[i]]=col[i];
}
System.Text.StringBuilder sb=new System.Text.StringBuilder();
for(i=0;i<newCol.Count;i++)
{
sb.Append("&");
sb.Append(newCol.Keys[i]);
sb.Append("=");
sb.Append(newCol[i]);
}
return String.Concat(currentUrl,"?",sb.ToString().Substring(1));
}
/// <summary>
/// 創建第一頁、上一頁、下一頁及最後一頁分頁按鈕。
/// </summary>
/// <param name="writer"><see cref="System.Web.UI.HtmlTextWriter"/>,表示要在客戶端呈現 HTML 內容的輸出流。</param>
/// <param name="btnname">分頁按鈕名。</param>
private void CreateNavigationButton(HtmlTextWriter writer,string btnname)
{
if(!ShowFirstLast&&(btnname=="first"||btnname=="last"))
return;
if(!ShowPrevNext&&(btnname=="prev"||btnname=="next"))
return;
string linktext="";
bool disabled;
int pageIndex;
bool imgButton=(PagingButtonType==PagingButtonType.Image&&NavigationButtonType==PagingButtonType.Image);
if(btnname=="prev"||btnname=="first")
{
disabled=(CurrentPageIndex<=1);
if(!ShowDisabledButtons&&disabled)
return;
pageIndex=(btnname=="first")?1:(CurrentPageIndex-1);
if(imgButton)
{
if(!disabled)
{
writer.AddAttribute(HtmlTextWriterAttribute.Href,GetHrefString(pageIndex));
AddToolTip(writer,pageIndex);
writer.RenderBeginTag(HtmlTextWriterTag.A);
writer.AddAttribute(HtmlTextWriterAttribute.Src,String.Concat(ImagePath,btnname,ButtonImageNameExtension,ButtonImageExtension));
writer.AddAttribute(HtmlTextWriterAttribute.Border,"0");
writer.AddAttribute(HtmlTextWriterAttribute.Align,ButtonImageAlign.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
writer.RenderEndTag();
}
else
{
writer.AddAttribute(HtmlTextWriterAttribute.Src,String.Concat(ImagePath,btnname,DisabledButtonImageNameExtension,ButtonImageExtension));
writer.AddAttribute(HtmlTextWriterAttribute.Border,"0");
writer.AddAttribute(HtmlTextWriterAttribute.Align,ButtonImageAlign.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
}
else
{
linktext=(btnname=="prev")?PrevPageText:FirstPageText;
if(disabled)
writer.AddAttribute(HtmlTextWriterAttribute.Disabled,"true");
else
{
WriteCssClass(writer);
AddToolTip(writer,pageIndex);
writer.AddAttribute(HtmlTextWriterAttribute.Href,GetHrefString(pageIndex));
}
writer.RenderBeginTag(HtmlTextWriterTag.A);
writer.Write(linktext);
writer.RenderEndTag();
}
}
else
{
disabled=(CurrentPageIndex>=PageCount);
if(!ShowDisabledButtons&&disabled)
return;
pageIndex=(btnname=="last")?PageCount:(CurrentPageIndex+1);
if(imgButton)
{
if(!disabled)
{
writer.AddAttribute(HtmlTextWriterAttribute.Href,GetHrefString(pageIndex));
AddToolTip(writer,pageIndex);
writer.RenderBeginTag(HtmlTextWriterTag.A);
writer.AddAttribute(HtmlTextWriterAttribute.Src,String.Concat(ImagePath,btnname,ButtonImageNameExtension,ButtonImageExtension));
writer.AddAttribute(HtmlTextWriterAttribute.Border,"0");
writer.AddAttribute(HtmlTextWriterAttribute.Align,ButtonImageAlign.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
writer.RenderEndTag();
}
else
{
writer.AddAttribute(HtmlTextWriterAttribute.Src,String.Concat(ImagePath,btnname,DisabledButtonImageNameExtension,ButtonImageExtension));
writer.AddAttribute(HtmlTextWriterAttribute.Border,"0");
writer.AddAttribute(HtmlTextWriterAttribute.Align,ButtonImageAlign.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
}
else
{
linktext=(btnname=="next")?NextPageText:LastPageText;
if(disabled)
writer.AddAttribute(HtmlTextWriterAttribute.Disabled,"true");
else
{
WriteCssClass(writer);
AddToolTip(writer,pageIndex);
writer.AddAttribute(HtmlTextWriterAttribute.Href,GetHrefString(pageIndex));
}
writer.RenderBeginTag(HtmlTextWriterTag.A);
writer.Write(linktext);
writer.RenderEndTag();
}
}
WriteButtonSpace(writer);
}
/// <summary>
/// 寫入CSS類名。
/// </summary>
/// <param name="writer"><see cref="System.Web.UI.HtmlTextWriter"/>,表示要在客戶端呈現 HTML 內容的輸出流。</param>
private void WriteCssClass(HtmlTextWriter writer)
{
if(cssClassName!=null&&cssClassName.Trim().Length>0)
writer.AddAttribute(HtmlTextWriterAttribute.Class,cssClassName);
}
/// <summary>
/// 加入導航按鈕提示文本。
/// </summary>
/// <param name="writer"><see cref="System.Web.UI.HtmlTextWriter"/>,表示要在客戶端呈現 HTML 內容的輸出流。</param>
/// <param name="pageIndex">導航按鈕對應的頁索引。</param>
private void AddToolTip(HtmlTextWriter writer,int pageIndex)
{
if(ShowNavigationToolTip)
{
writer.AddAttribute(HtmlTextWriterAttribute.Title,String.Format(NavigationToolTipTextFormatString,pageIndex));
}
}
/// <summary>
/// 創建分頁數值導航按鈕。
/// </summary>
/// <param name="writer"><see cref="System.Web.UI.HtmlTextWriter"/>,表示要在客戶端呈現 HTML 內容的輸出流。</param>
/// <param name="index">要創建按鈕的頁索引的值。</param>
private void CreateNumericButton(HtmlTextWriter writer,int index)
{
bool isCurrent=(index==CurrentPageIndex);
if(PagingButtonType==PagingButtonType.Image&&NumericButtonType==PagingButtonType.Image)
{
if(!isCurrent)
{
writer.AddAttribute(HtmlTextWriterAttribute.Href,GetHrefString(index));
AddToolTip(writer,index);
writer.RenderBeginTag(HtmlTextWriterTag.A);
CreateNumericImages(writer,index,isCurrent);
writer.RenderEndTag();
}
else
CreateNumericImages(writer,index,isCurrent);
}
else
{
if(isCurrent)
{
writer.AddStyleAttribute(HtmlTextWriterStyle.FontWeight,"Bold");
writer.AddStyleAttribute(HtmlTextWriterStyle.Color,"red");
writer.RenderBeginTag(HtmlTextWriterTag.Font);
if(NumericButtonTextFormatString.Length>0)
writer.Write(String.Format(NumericButtonTextFormatString,(ChinesePageIndex==true)?GetChinesePageIndex(index):(index.ToString())));
else
writer.Write((ChinesePageIndex==true)?GetChinesePageIndex(index):index.ToString());
writer.RenderEndTag();
}
else
{
WriteCssClass(writer);
AddToolTip(writer,index);
writer.AddAttribute(HtmlTextWriterAttribute.Href,GetHrefString(index));
writer.RenderBeginTag(HtmlTextWriterTag.A);
if(NumericButtonTextFormatString.Length>0)
writer.Write(String.Format(NumericButtonTextFormatString,(ChinesePageIndex==true)?GetChinesePageIndex(index):(index.ToString())));
else
writer.Write((ChinesePageIndex==true)?GetChinesePageIndex(index):index.ToString());
writer.RenderEndTag();
}
}
WriteButtonSpace(writer);
}
/// <summary>
/// 在分頁導航元素間加入空格。
/// </summary>
/// <param name="writer"></param>
private void WriteButtonSpace(HtmlTextWriter writer)
{
if(PagingButtonSpacing.Value>0)
{
writer.AddStyleAttribute(HtmlTextWriterStyle.Width,PagingButtonSpacing.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.RenderEndTag();
}
}
/// <summary>
/// 獲取中文頁索引字符。
/// </summary>
/// <param name="index">中文字符對應的頁索引數值</param>
/// <returns>對應於頁索引數值的中文字符</returns>
private string GetChinesePageIndex(int index)
{
Hashtable cnChars=new Hashtable();
cnChars.Add("0","O");
cnChars.Add("1","一");
cnChars.Add("2","二");
cnChars.Add("3","三");
cnChars.Add("4","四");
cnChars.Add("5","五");
cnChars.Add("6","六");
cnChars.Add("7","七");
cnChars.Add("8","八");
cnChars.Add("9","九");
string indexStr=index.ToString();
string retStr="";
for(int i=0;i<indexStr.Length;i++)
{
retStr=String.Concat(retStr,cnChars[indexStr[i].ToString()]);
}
return retStr;
}
/// <summary>
/// 創建頁索引圖片按鈕。
/// </summary>
/// <param name="writer"><see cref="System.Web.UI.HtmlTextWriter"/>,表示要在客戶端呈現 HTML 內容的輸出流。</param>
/// <param name="index">頁索引數值。</param>
/// <param name="isCurrent">是否是當前頁索引。</param>
private void CreateNumericImages(HtmlTextWriter writer,int index,bool isCurrent)
{
string indexStr=index.ToString();
for(int i=0;i<indexStr.Length;i++)
{
writer.AddAttribute(HtmlTextWriterAttribute.Src,String.Concat(ImagePath,indexStr[i],(isCurrent==true)?CpiButtonImageNameExtension:ButtonImageNameExtension,ButtonImageExtension));
writer.AddAttribute(HtmlTextWriterAttribute.Align,ButtonImageAlign.ToString());
writer.AddAttribute(HtmlTextWriterAttribute.Border,"0");
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
}
/// <summary>
/// 創建“更多頁”(...)按鈕。
/// </summary>
/// <param name="writer"><see cref="System.Web.UI.HtmlTextWriter"/>,表示要在客戶端呈現 HTML 內容的輸出流。</param>
/// <param name="pageIndex">鏈接到按鈕的頁的索引。</param>
private void CreateMoreButton(HtmlTextWriter writer,int pageIndex)
{
WriteCssClass(writer);
writer.AddAttribute(HtmlTextWriterAttribute.Href,GetHrefString(pageIndex));
AddToolTip(writer,pageIndex);
writer.RenderBeginTag(HtmlTextWriterTag.A);
if(PagingButtonType==PagingButtonType.Image&&MoreButtonType==PagingButtonType.Image)
{
writer.AddAttribute(HtmlTextWriterAttribute.Src,String.Concat(ImagePath,"more",ButtonImageNameExtension,ButtonImageExtension));
writer.AddAttribute(HtmlTextWriterAttribute.Border,"0");
writer.AddAttribute(HtmlTextWriterAttribute.Align,ButtonImageAlign.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
else
writer.Write("...");
writer.RenderEndTag();
writer.AddStyleAttribute(HtmlTextWriterStyle.Width,PagingButtonSpacing.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.RenderEndTag();
}
#endregion
#region IPostBackEventHandler Implementation
/// <summary>
/// 實現<see cref="IPostBackEventHandler"/> 接口,使 <see cref="AspNetPager"/> 控件能夠處理將窗體發送到服務器時引發的事件。
/// </summary>
/// <param name="args"></param>
public void RaisePostBackEvent(string args)
{
int pageIndex=CurrentPageIndex;
try
{
if(args==null||args=="")
args=inputPageIndex;
pageIndex=int.Parse(args);
}
catch{}
OnPageChanged(new PageChangedEventArgs(pageIndex));
}
#endregion
當前1/2頁
12下一頁閱讀全文