AspNetPager分页控件--使用方法 1


 //此源代码仅供学习参考,不得用作任何商业用途;
  //若需修改并重新编译该控件,请保留完整的源代码的版权信息!
  //有关控件升级及新控件发布信息,请留意 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.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(yhaili@21cn.com)">
  /// </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等将会被中文字符一、

转载于:https://www.cnblogs.com/think-jerry/archive/2007/05/28/762108.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值