ASP.NET分页控件_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > ASP.NET分页控件

ASP.NET分页控件

 2013/10/30 9:58:42  web8  博客园  我要评论(0)
  • 摘要:效果图这个在用户控件一用一次<%@RegisterAssembly="Uni2Uni.ERP.Common"Namespace="Uni2Uni.ERP.Common.PageBar"TagPrefix="cc1"%><cc1:PageBarID="pageBar"runat="server"Mode="Post"/>然后使用那个用户控件<uc1:PageBarControlID="PageBarControl1"runat="server"/>
  • 标签:.net ASP.NET net 控件

效果图

这个在用户控件一用一次

<%@ Register Assembly="Uni2Uni.ERP.Common" Namespace="Uni2Uni.ERP.Common.PageBar"
    TagPrefix="cc1" %>
<cc1:PageBar ID="pageBar" runat="server" Mode="Post" />

 

 

然后使用那个用户控件


    class="dp-xml" start="1">
  1. <uc1:PageBarControl ID="PageBarControl1" runat="server" />  
  2.   
  3.   
  4. PageBarControl1.PageBar.Click += new EventHandler(PagerChange);  
  5.           
  6.   
  7.         private void PagerChange(object sender, EventArgs e)  
  8.         {  
  9.             var queryEntity = ViewState["queryEntity"] as DamagedQueryEntity;  
  10.             GetPageData(queryEntity, false);  
  11.         }  
  12.   
  13.   
  14.  private void GetPageData(DamagedQueryEntity queryEntity, bool bFirst = true)  
  15.         {  
  16.             if (bFirst)  
  17.                 PageBarControl1.PageBar.CurrentIndex = 1;  
  18.             int totalCount;  
  19.             var list = bll.GetDamagedOrderPage(PageBarControl1.PageBar.CurrentIndex, PageBarControl1.PageBar.Size, out totalCount, queryEntity);  
  20.             this.PageBarControl1.PageBar.Total = totalCount;  
  21.             this.bindData.DataSource = list;  
  22.             this.bindData.DataBind();  
  23.         }  


 

源码


  1. using System;  
  2. using System.Collections.Specialized;  
  3. using System.ComponentModel;  
  4. using System.Text;  
  5. using System.Text.RegularExpressions;  
  6. using System.Web.UI;  
  7. using System.Web.UI.HtmlControls;  
  8. using System.Web.UI.WebControls;  
  9.   
  10. [assembly: WebResource("Uni2Uni.ERP.Common.PageBar.PageBar.css", "text/css", PerformSubstitution = true)]  
  11.   
  12. namespace Uni2Uni.ERP.Common.PageBar  
  13. {  
  14.     public enum PageBarMode  
  15.     {  
  16.         Get,  
  17.         Post  
  18.     }  
  19.   
  20.     #region - PageBar -  
  21.   
  22.     /// <summary>  
  23.     /// 分页控件  
  24.     /// </summary>  
  25.     [ToolboxData("<{0}:PageBar runat=\"server\" />")]  
  26.     [DefaultEvent("Click")]  
  27.     [DefaultProperty("Size")]  
  28.     public sealed class PageBar : WebControl, IPostBackEventHandler  
  29.     {  
  30.         #region - Properties -  
  31.   
  32.         #region = Total =  
  33.   
  34.         /// <summary>  
  35.         /// 总共有多少记录集合  
  36.         /// </summary>  
  37.         /// <value>The total.</value>  
  38.         [Category("Data"), Description("总共有多少记录集合")]  
  39.         public int Total  
  40.         {  
  41.             get  
  42.             {  
  43.                 object o = ViewState["Total"];  
  44.                 return o == null ? 0 : (int)o;  
  45.             }  
  46.             set { ViewState["Total"] = value; }  
  47.         }  
  48.   
  49.         #endregion  
  50.   
  51.         #region = CurrentIndex =  
  52.   
  53.         /// <summary>  
  54.         /// 当前使用的页面  
  55.         /// </summary>  
  56.         /// <value>The index of the current.</value>  
  57.         [Category("Data"), Description("当前使用的页面")]  
  58.         public int CurrentIndex  
  59.         {  
  60.             get  
  61.             {  
  62.                 object o = ViewState["CurrentIndex"];  
  63.                 int _currentindex = ((o == null) ? 0 : (int)o);  
  64.                 if (_currentindex == 0)  
  65.                 {  
  66.                     _currentindex = 1;  
  67.   
  68.                     if (string.IsNullOrEmpty(UrlFormatString) == false)  
  69.                     {  
  70.                         string url = Page.Request.Url.ToString();  
  71.                         string urlformat = string.Format(UrlFormatString, @"(\d+)");  
  72.                         urlformat = urlformat.Replace("?", "\\?");  
  73.                         urlformat = Regex.Replace(urlformat, "#.+$", string.Empty);  
  74.   
  75.                         Match m = Regex.Match(url, urlformat, RegexOptions.IgnoreCase);  
  76.   
  77.                         if (m.Success)  
  78.                         {  
  79.                             string value = m.Groups[1].Value;  
  80.                             if (string.IsNullOrEmpty(value) == false)  
  81.                             {  
  82.                                 _currentindex = int.Parse(value);  
  83.                             }  
  84.                         }  
  85.                     }  
  86.                     else  
  87.                     {  
  88.                         if (Page.Request.QueryString[QueryStringKey] != null)  
  89.                         {  
  90.                             int.TryParse(Page.Request.QueryString[QueryStringKey], out _currentindex);  
  91.                         }  
  92.                     }  
  93.                 }  
  94.                 return _currentindex;  
  95.             }  
  96.             set { ViewState["CurrentIndex"] = value; }  
  97.         }  
  98.   
  99.         #endregion  
  100.   
  101.         #region = Size =  
  102.   
  103.         /// <summary>  
  104.         /// 每个页面显示多少记录集合  
  105.         /// </summary>  
  106.         /// <value>The size.</value>  
  107.         [Category("Data"), Description("每个页面显示多少记录集合")]  
  108.         public int Size  
  109.         {  
  110.             get  
  111.             {  
  112.                 object o = ViewState["Size"];  
  113.                 return o == null ? 10 : (int)o;  
  114.             }  
  115.             set { ViewState["Size"] = value; }  
  116.         }  
  117.   
  118.         #endregion  
  119.   
  120.         #region = Displaysize =  
  121.   
  122.         /// <summary>  
  123.         /// 显示页脚,控件显示多少页面数  
  124.         /// </summary>  
  125.         /// <value>The displaysize.</value>  
  126.         [Category("Data"), Description("控件显示多少页面数")]  
  127.         public int Displaysize  
  128.         {  
  129.             get  
  130.             {  
  131.                 object o = ViewState["Displaysize"];  
  132.                 return o == null ? 10 : (int)o;  
  133.             }  
  134.             set { ViewState["Displaysize"] = value; }  
  135.         }  
  136.   
  137.         #endregion  
  138.   
  139.         #region = Unit =  
  140.   
  141.         /// <summary>  
  142.         /// 记录的单位  
  143.         /// </summary>  
  144.         /// <value>The unit.</value>  
  145.         [Category("Appearance"), Description("记录的单位")]  
  146.         public string Unit  
  147.         {  
  148.             get  
  149.             {  
  150.                 object o = ViewState["Unit"];  
  151.                 return o == null ? string.Empty : (string)o;  
  152.             }  
  153.             set { ViewState["Unit"] = value; }  
  154.         }  
  155.   
  156.         #endregion  
  157.   
  158.         #region = UrlFormatString =  
  159.   
  160.         [  
  161.             Category("Property"),  
  162.             Description("获取或设置 URL 显示格式。"),  
  163.             DefaultValue("")  
  164.         ]  
  165.         public string UrlFormatString  
  166.         {  
  167.             get  
  168.             {  
  169.                 object o = ViewState["UrlFormatString"];  
  170.                 return o == null ? string.Empty : (string)o;  
  171.             }  
  172.             set { ViewState["UrlFormatString"] = value; }  
  173.         }  
  174.   
  175.         #endregion  
  176.   
  177.         #region = QueryStringKey =  
  178.   
  179.         /// <summary>  
  180.         /// 传递值是使用的关键字  
  181.         /// </summary>  
  182.         /// <value>The query string key.</value>  
  183.         [Description("传递值是使用的关键字"), DefaultValue("page")]  
  184.         public string QueryStringKey  
  185.         {  
  186.             get  
  187.             {  
  188.                 object o = ViewState["QueryStringKey"];  
  189.                 return o == null ? "page" : (string)o;  
  190.             }  
  191.             set { ViewState["QueryStringKey"] = value; }  
  192.         }  
  193.   
  194.         #endregion  
  195.   
  196.         #region = 跳转的页数 =  
  197.         /// <summary>  
  198.         /// 跳转的页数  
  199.         /// </summary>  
  200.         [Browsable(true)]  
  201.         [Bindable(true, BindingDirection.TwoWay)]  
  202.         [DefaultValue("")]  
  203.         [Localizable(true)]  
  204.         [PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty)]  
  205.         [Description("跳转的页数")]  
  206.         public string Text  
  207.         {  
  208.             get  
  209.             {  
  210.                 return ViewState["Text"] == null ? "" : ViewState["Text"].ToString();  
  211.             }  
  212.             set  
  213.             {  
  214.                 ViewState["Text"] = value;  
  215.             }  
  216.         }  
  217.         #endregion  
  218.   
  219.         #region = Format =  
  220.   
  221.         /// <summary>  
  222.         /// 数字格式化  
  223.         /// </summary>  
  224.         /// <value>The format.</value>  
  225.         [Description("数字格式化"), DefaultValue("")]  
  226.         public string Format  
  227.         {  
  228.             get  
  229.             {  
  230.                 object o = ViewState["Format"];  
  231.                 return o == null ? string.Empty : (string)o;  
  232.             }  
  233.             set { ViewState["Format"] = value; }  
  234.         }  
  235.   
  236.         #endregion  
  237.   
  238.         #region = NextPageImageUrl =  
  239.   
  240.         /// <summary>  
  241.         /// 下一页图片路径  
  242.         /// </summary>  
  243.         /// <value>The next page image URL.</value>  
  244.         [Description("下一页图片路径"), DefaultValue("")]  
  245.         public string NextPageImageUrl  
  246.         {  
  247.             get  
  248.             {  
  249.                 object o = ViewState["NextPageImageUrl"];  
  250.                 return o == null ? string.Empty : (string)o;  
  251.             }  
  252.             set { ViewState["NextPageImageUrl"] = value; }  
  253.         }  
  254.   
  255.         #endregion  
  256.   
  257.         #region = LastPageImageUrl =  
  258.   
  259.         private string _lastimage = string.Empty;  
  260.   
  261.         /// <summary>  
  262.         /// 上一页图片路径  
  263.         /// </summary>  
  264.         /// <value>The last page image URL.</value>  
  265.         [Description("上一页图片路径"), DefaultValue("")]  
  266.         public string LastPageImageUrl  
  267.         {  
  268.             get  
  269.             {  
  270.                 object o = ViewState["LastPageImageUrl"];  
  271.                 return o == null ? string.Empty : (string)o;  
  272.             }  
  273.             set { ViewState["LastPageImageUrl"] = value; }  
  274.         }  
  275.   
  276.         #endregion  
  277.   
  278.         #region = Mode =  
  279.   
  280.         [  
  281.             Category("Property"),  
  282.             Description("Pagebar的模式"),  
  283.             DefaultValue("")  
  284.         ]  
  285.         public PageBarMode Mode  
  286.         {  
  287.             get  
  288.             {  
  289.                 object o = ViewState["Mode"];  
  290.                 return o == null ? PageBarMode.Get : (PageBarMode)o;  
  291.             }  
  292.             set { ViewState["Mode"] = value; }  
  293.         }  
  294.   
  295.         #endregion  
  296.   
  297.         #region = ValidationGroup =  
  298.   
  299.         [Category("Behavior"), DefaultValue(""), Themeable(false), Description("PostBackControl_ValidationGroup")]  
  300.         public string ValidationGroup  
  301.         {  
  302.             get  
  303.             {  
  304.                 var text1 = (string)ViewState["ValidationGroup"];  
  305.                 if (text1 != null)  
  306.                 {  
  307.                     return text1;  
  308.                 }  
  309.                 return string.Empty;  
  310.             }  
  311.             set { ViewState["ValidationGroup"] = value; }  
  312.         }  
  313.   
  314.         #endregion  
  315.   
  316.         #region = CausesValidation =  
  317.   
  318.         /// <summary>  
  319.         /// 获取或设置一个值,该值指示在单击 LinkButton 控件时是否执行验证。   
  320.         /// </summary>  
  321.         /// <value><c>true</c> if [causes validation]; otherwise, <c>false</c>.</value>  
  322.         [Category("Behavior"), Themeable(false), Description("Button_CausesValidation"), DefaultValue(true)]  
  323.         public bool CausesValidation  
  324.         {  
  325.             get  
  326.             {  
  327.                 object obj1 = ViewState["CausesValidation"];  
  328.                 if (obj1 != null)  
  329.                 {  
  330.                     return (bool)obj1;  
  331.                 }  
  332.                 return true;  
  333.             }  
  334.             set { ViewState["CausesValidation"] = value; }  
  335.         }  
  336.   
  337.         #endregion  
  338.   
  339.         #region = Target =  
  340.   
  341.         /// <summary>  
  342.         /// Gets or sets the target.  
  343.         /// </summary>  
  344.         /// <value>The target.</value>  
  345.         [  
  346.             Category("Navigation"),  
  347.             TypeConverter(typeof(TargetConverter)),  
  348.             DefaultValue(""),  
  349.             Description("HyperLink_Target")]  
  350.         public string Target  
  351.         {  
  352.             get  
  353.             {  
  354.                 var text1 = (string)ViewState["Target"];  
  355.                 if (text1 != null)  
  356.                 {  
  357.                     return text1;  
  358.                 }  
  359.                 return "_self";  
  360.             }  
  361.             set { ViewState["Target"] = value; }  
  362.         }  
  363.   
  364.         #endregion  
  365.   
  366.         #endregion  
  367.   
  368.         #region - Event -  
  369.   
  370.         #region = OnClick =  
  371.   
  372.         private static readonly object EventClick = new object();  
  373.   
  374.         [Description("PageBar_OnClick"), Category("Action")]  
  375.         public event EventHandler Click  
  376.         {  
  377.             add { Events.AddHandler(EventClick, value); }  
  378.             remove { Events.RemoveHandler(EventClick, value); }  
  379.         }  
  380.   
  381.         #endregion  
  382.   
  383.         #endregion  
  384.   
  385.         #region = OnPreRender =  
  386.   
  387.         /// <summary>  
  388.         /// Raises the <see cref="E:System.Web.UI.Control.PreRender"></see> event.  
  389.         /// </summary>  
  390.         /// <param name="e">An <see cref="T:System.EventArgs"></see> object that contains the event data.</param>  
  391.         protected override void OnPreRender(EventArgs e)  
  392.         {  
  393.             base.OnPreRender(e);  
  394.   
  395.             string cssKey = "PageBarCss";  
  396.   
  397.             if (Page == null || Page.Header == null)  
  398.             {  
  399.                 return;  
  400.             }  
  401.             if (string.IsNullOrEmpty(CssClass))  
  402.             {  
  403.                 CssClass = "PageBar";  
  404.             }  
  405.             if (Page.Header.FindControl(cssKey) == null && CssClass == "PageBar")  
  406.             {  
  407.                 string css = Page.ClientScript.GetWebResourceUrl(GetType(), "Uni2Uni.ERP.Common.PageBar.PageBar.css");  
  408.                 var hl = new HtmlLink();  
  409.                 hl.ID = cssKey;  
  410.                 hl.Href = css;  
  411.                 hl.Attributes["type"] = "text/css";  
  412.                 hl.Attributes["rel"] = "stylesheet";  
  413.   
  414.                 //this.Page.Header.Controls.Add(hl);  
  415.   
  416.                 CssClass = "PageBar";  
  417.             }  
  418.         }  
  419.   
  420.         #endregion  
  421.   
  422.         #region = RenderContents =  
  423.   
  424.         /// <summary>  
  425.         /// Renders the contents of the control to the specified writer. This method is used primarily by control developers.  
  426.         /// </summary>  
  427.         /// <param name="writer"><see cref="T:System.Web.UI.HtmlTextWriter"></see> that represents the output stream to render HTML content on the client.</param>  
  428.         protected override void RenderContents(HtmlTextWriter writer)  
  429.         {  
  430.             base.RenderContents(writer);  
  431.   
  432.             #region - Valid -  
  433.   
  434.             if (IsEnabled == false)  
  435.             {  
  436.                 return;  
  437.             }  
  438.   
  439.             if (Size == 0 || Displaysize == 0)  
  440.             {  
  441.                 return;  
  442.             }  
  443.   
  444.             #endregion  
  445.   
  446.             if (Total > 0 && CurrentIndex > 0)  
  447.             {  
  448.                 double dPageCount = 1.0 * Total / Size;  
  449.                 int PageCount = Convert.ToInt32(Math.Ceiling(dPageCount)); //共多少页  
  450.   
  451.                 PostBackOptions options = GetPostBackOptions("{0}");  
  452.                 string srt = Page.ClientScript.GetPostBackEventReference(options, true);  
  453.   
  454.                 //---【新添加】  
  455.                 //只能输入正整数  
  456.                 string js = "<script type=\"text/javascript\">var postbackstring=\"" + srt + "\";var total=" + PageCount + "function PositiveInteger(element, keyCode) {if (keyCode == 9 || keyCode == 116 || (keyCode >= 35 && keyCode <= 40)) {return true;}if ($(element).val().length == 0 && (keyCode == 96 || keyCode==48)){return false;}return (keyCode >= 96 && keyCode <= 105 || keyCode == 8 || (keyCode >= 48 && keyCode <= 57));}function validatePage(element){if($(\"#goPage\").val()==\"\"){alert(\"请输入跳转页数。\");return false;}if($(\"#goPage\").val()>total){alert(\"跳转页数不能大于总页数。\");return false;}$(element).attr(\"href\",postbackstring.replace(\"{0}\",$(\"#goPage\").val()));return true;}</script>";  
  457.                 writer.Write(js);  
  458.   
  459.                 if (CurrentIndex > PageCount)  
  460.                 {  
  461.                     CurrentIndex = PageCount;  
  462.                 }  
  463.   
  464.                 //总共2784主题  
  465.                 writer.Write(PageBarResource.Total);  
  466.                 //writer.Write("总共");  
  467.                 writer.Write(" ");  
  468.                 writer.RenderBeginTag(HtmlTextWriterTag.Label);  
  469.                 writer.Write(Total.ToString(Format));  
  470.                 writer.RenderEndTag();  
  471.                 writer.Write(Unit);  
  472.                 writer.Write(", ");  
  473.   
  474.                 writer.Write(PageBarResource.Page);  
  475.                 //writer.Write("当前");  
  476.                 writer.Write(" ");  
  477.                 writer.RenderBeginTag(HtmlTextWriterTag.Label);  
  478.                 writer.Write(CurrentIndex.ToString(Format));  
  479.                 writer.RenderEndTag();  
  480.                 writer.Write("/");  
  481.                 writer.RenderBeginTag(HtmlTextWriterTag.Label);  
  482.                 writer.Write(PageCount.ToString(Format));  
  483.                 writer.RenderEndTag();  
  484.   
  485.                 if (PageCount > 1)  
  486.                 {  
  487.                     writer.Write(",");  
  488.                     int PagerGroup = Convert.ToInt32(Math.Ceiling(1.0 * PageCount / Displaysize)); //共多少页组  
  489.                     int CurrentGroup = (CurrentIndex - 1) / Displaysize + 1; //当前页组  
  490.   
  491.                     int displaystart = (CurrentGroup - 1) * Displaysize + 1;  
  492.                     int displayend = displaystart + Displaysize;  
  493.   
  494.                     if (displayend > (PageCount + 1))  
  495.                     {  
  496.                         displayend = PageCount + 1;  
  497.                     }  
  498.   
  499.                     #region 显示后三的算法----------【新添加】  
  500.                     ////显示后三的算法----------【新添加】  
  501.                     //if (PageCount > Displaysize && CurrentIndex > Displaysize - 3)  
  502.                     //{  
  503.                     //    displaystart = CurrentIndex - (Displaysize - 4);  
  504.                     //    displayend = CurrentIndex + 4;  
  505.                     //    if (displayend - 1 >= PageCount)  
  506.                     //    {  
  507.                     //        displayend = PageCount + 1;  
  508.                     //    }  
  509.                     //}   
  510.                     #endregion  
  511.   
  512.   
  513.                     //显示中间的算法----------【新添加】  
  514.                     if (PageCount > Displaysize && CurrentIndex >= Displaysize - ((Displaysize / 2) - 1))  
  515.                     {  
  516.                         displaystart = CurrentIndex - (Displaysize - (Displaysize / 2));  
  517.                         displayend = CurrentIndex + (Displaysize / 2);  
  518.                         if (displayend - 1 >= PageCount)  
  519.                         {  
  520.                             displayend = PageCount + 1;  
  521.                         }  
  522.                     }  
  523.   
  524.                     //首页-------【新添加】  
  525.                     if (CurrentIndex != 1)  
  526.                     {  
  527.                         writer.RenderBeginTag(HtmlTextWriterTag.Span);  
  528.                         LinkText("【首页】", 1, writer);  
  529.                         writer.RenderEndTag();  
  530.                     }  
  531.                     else  
  532.                     {  
  533.                         //---【新添加】  
  534.                         writer.RenderBeginTag(HtmlTextWriterTag.Label);  
  535.                         writer.Write("【首页】");  
  536.                         writer.RenderEndTag();  
  537.                     }  
  538.                     //上一页  
  539.                     if (CurrentIndex > 1)  
  540.                     {  
  541.                         writer.RenderBeginTag(HtmlTextWriterTag.Span);  
  542.                         if (string.IsNullOrEmpty(LastPageImageUrl))  
  543.                         {  
  544.                             LinkText(PageBarResource.Previous, CurrentIndex - 1, writer);  
  545.                             //LinkText("【上一页】", this.CurrentIndex - 1, writer);  
  546.                         }  
  547.                         else  
  548.                         {  
  549.                             LinkText(  
  550.                                 "<img alt=\"" + PageBarResource.Previous + "\" src=\"" + LastPageImageUrl + "\" />",  
  551.                                 CurrentIndex - 1, writer);  
  552.                             //LinkText("<img alt=\"" +"【上一页】" + "\" src=\"" + this.LastPageImageUrl + "\" />", this.CurrentIndex - 1, writer);  
  553.                         }  
  554.                         writer.RenderEndTag();  
  555.                     }  
  556.                     else    
  557.                     {  
  558.                         //---【新添加】  
  559.                         writer.RenderBeginTag(HtmlTextWriterTag.Label);  
  560.                         writer.Write("【上一页】");  
  561.                         writer.RenderEndTag();  
  562.                     }  
  563.   
  564.                     //上一组  
  565.                     if (CurrentGroup > 1 || displaystart != 1)  
  566.                     {  
  567.                         writer.AddAttribute(HtmlTextWriterAttribute.Title, "上"+Displaysize+"页");  
  568.                         writer.RenderBeginTag(HtmlTextWriterTag.Span);  
  569.                         int index = CurrentIndex - Displaysize;  
  570.                         if (index < 1)  
  571.                         {  
  572.                             index = 1;  
  573.                         }  
  574.                         LinkText("<<", index, writer);  
  575.                         writer.RenderEndTag();  
  576.                     }  
  577.                     else  
  578.                     {  
  579.                         //---【新添加】  
  580.                         writer.RenderBeginTag(HtmlTextWriterTag.Label);  
  581.                         writer.Write("<<");  
  582.                         writer.RenderEndTag();  
  583.                     }  
  584.                     string attr = string.Empty;  
  585.   
  586.                     //显示数字  
  587.                     for (int i = displaystart; i < displayend; i++)  
  588.                     {  
  589.                         writer.RenderBeginTag(HtmlTextWriterTag.Span);  
  590.                         if (i != CurrentIndex)  
  591.                         {  
  592.                             LinkText(i.ToString() + " ", i, writer);  
  593.                         }  
  594.                         else  
  595.                         {  
  596.                             //当前页  
  597.                             writer.RenderBeginTag(HtmlTextWriterTag.Label);  
  598.                             writer.Write(i + " ");  
  599.                             writer.RenderEndTag();  
  600.                         }  
  601.                         writer.RenderEndTag();  
  602.                     }  
  603.   
  604.                       
  605.                     //下一组  
  606.                     if (displayend - 1 < PageCount)  
  607.                     {  
  608.                         writer.AddAttribute(HtmlTextWriterAttribute.Title, "下" + Displaysize + "页");  
  609.                         writer.RenderBeginTag(HtmlTextWriterTag.Span);  
  610.                         int index = CurrentIndex + Displaysize;  
  611.                         if (index > PageCount)  
  612.                         {  
  613.                             index = PageCount;  
  614.                         }  
  615.                         LinkText(">>", index, writer);  
  616.                         writer.RenderEndTag();  
  617.                     }  
  618.                     else  
  619.                     {  
  620.                         //---【新添加】  
  621.                         writer.RenderBeginTag(HtmlTextWriterTag.Label);  
  622.                         writer.Write(">>");  
  623.                         writer.RenderEndTag();  
  624.                     }  
  625.   
  626.                     //下一页  
  627.                     if (CurrentIndex < PageCount)  
  628.                     {  
  629.                         writer.RenderBeginTag(HtmlTextWriterTag.Span);  
  630.                         if (string.IsNullOrEmpty(NextPageImageUrl))  
  631.                         {  
  632.                             LinkText(PageBarResource.Next, CurrentIndex + 1, writer);  
  633.                             //LinkText("【下一页】", this.CurrentIndex + 1, writer);  
  634.                         }  
  635.                         else  
  636.                         {  
  637.                             LinkText("<img alt=\"" + PageBarResource.Next + "\" src=\"" + NextPageImageUrl + "\" />",  
  638.                                      CurrentIndex + 1, writer);  
  639.                             //LinkText("<img alt=\"" + "【下一页】" + "\" src=\"" + this.NextPageImageUrl + "\" />", this.CurrentIndex + 1, writer);  
  640.                         }  
  641.                         writer.RenderEndTag();  
  642.                     }  
  643.                     else  
  644.                     {  
  645.                         //---【新添加】  
  646.                         writer.RenderBeginTag(HtmlTextWriterTag.Label);  
  647.                         writer.Write("【下一页】");  
  648.                         writer.RenderEndTag();  
  649.                     }  
  650.   
  651.                     //尾页-------【新添加】  
  652.                     if (CurrentIndex != PageCount)  
  653.                     {  
  654.                         writer.RenderBeginTag(HtmlTextWriterTag.Span);  
  655.                         LinkText("【尾页】", PageCount, writer);  
  656.                         writer.RenderEndTag();  
  657.                     }  
  658.                     else  
  659.                     {  
  660.                         //---【新添加】  
  661.                         writer.RenderBeginTag(HtmlTextWriterTag.Label);  
  662.                         writer.Write("【尾页】");  
  663.                         writer.RenderEndTag();  
  664.                     }  
  665.   
  666.   
  667.                     //跳转---【新添加】  
  668.                     if (PagerGroup > 1)  
  669.                     {  
  670.                         writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");  
  671.                         writer.AddAttribute(HtmlTextWriterAttribute.Id, "goPage");  
  672.                         writer.AddAttribute(HtmlTextWriterAttribute.Value, Text);  
  673.                         writer.AddAttribute("onkeydown", "return PositiveInteger(this,event.keyCode);");  
  674.                         writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "10px");  
  675.                         writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "40px");  
  676.                         writer.AddStyleAttribute(HtmlTextWriterStyle.Position, "relative");  
  677.                         writer.AddStyleAttribute(HtmlTextWriterStyle.Top, "4px");  
  678.                         writer.AddAttribute(HtmlTextWriterAttribute.Maxlength, PageCount.ToString().Length.ToString());  
  679.                         writer.RenderBeginTag(HtmlTextWriterTag.Input);  
  680.                         writer.RenderEndTag();  
  681.   
  682.                         writer.AddAttribute("onclick", "return validatePage(this);");  
  683.                         writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:void(0)");  
  684.                         writer.RenderBeginTag(HtmlTextWriterTag.A);  
  685.                         writer.Write("【跳转】");  
  686.                         writer.RenderEndTag();  
  687.                     }  
  688.   
  689.                 }  
  690.             }  
  691.             else  
  692.             {  
  693.                 Visible = false;  
  694.             }  
  695.         }  
  696.   
  697.         #endregion  
  698.   
  699.         #region - LinkText -  
  700.   
  701.         private void LinkText(string text, int index, HtmlTextWriter write)  
  702.         {  
  703.             var strHtml = new StringBuilder();  
  704.             //href  
  705.             if (Mode == PageBarMode.Get)  
  706.             {  
  707.                 #region = 获取和解析当前的url =  
  708.   
  709.                 if (string.IsNullOrEmpty(UrlFormatString))  
  710.                 {  
  711.                     strHtml.Append(UrlHelper.Current.Path);  
  712.                     strHtml.Append("?");  
  713.                     NameValueCollection querys = Page.Request.QueryString;  
  714.   
  715.                     foreach (string s in querys.Keys)  
  716.                     {  
  717.                         if (s != QueryStringKey)  
  718.                         {  
  719.                             strHtml.AppendFormat("{0}={1}&", s, Page.Server.UrlEncode(querys[s]));  
  720.                         }  
  721.                     }  
  722.   
  723.                     strHtml.AppendFormat("{0}={1}", QueryStringKey, index);  
  724.                 }  
  725.                 else  
  726.                 {  
  727.                     strHtml.AppendFormat(UrlFormatString, index);  
  728.                 }  
  729.   
  730.                 #endregion  
  731.             }  
  732.             else  
  733.             {  
  734.                 PostBackOptions options = GetPostBackOptions(index.ToString());  
  735.   
  736.                 string js = null;  
  737.                 if (options != null)  
  738.                 {  
  739.                     js = Page.ClientScript.GetPostBackEventReference(options, true);  
  740.                 }  
  741.                 if (string.IsNullOrEmpty(js))  
  742.                 {  
  743.                     js = "javascript:void(0)";  
  744.                 }  
  745.                 strHtml.Append(js);  
  746.             }  
  747.   
  748.             //text  
  749.             write.AddAttribute(HtmlTextWriterAttribute.Href, strHtml.ToString());  
  750.             if (Mode == PageBarMode.Get)  
  751.             {  
  752.                 write.AddAttribute(HtmlTextWriterAttribute.Target, Target);  
  753.             }  
  754.             write.RenderBeginTag(HtmlTextWriterTag.A);  
  755.             write.Write(text);  
  756.             write.RenderEndTag();  
  757.         }  
  758.   
  759.         #endregion  
  760.   
  761.         #region - GetPostBackOptions -  
  762.   
  763.         private PostBackOptions GetPostBackOptions(string index)  
  764.         {  
  765.             var options1 = new PostBackOptions(this, index);  
  766.             options1.RequiresJavaScriptProtocol = true;  
  767.   
  768.             if (CausesValidation && (Page.GetValidators(ValidationGroup).Count > 0))  
  769.             {  
  770.                 options1.PerformValidation = true;  
  771.                 options1.ValidationGroup = ValidationGroup;  
  772.             }  
  773.             return options1;  
  774.         }  
  775.   
  776.         #endregion  
  777.   
  778.         #region - OnClick -  
  779.   
  780.         private void OnClick(EventArgs e)  
  781.         {  
  782.             var handler1 = (EventHandler)base.Events[EventClick];  
  783.             if (handler1 != null)  
  784.             {  
  785.                 handler1(this, e);  
  786.             }  
  787.         }  
  788.   
  789.         #endregion  
  790.   
  791.         #region IPostBackEventHandler Members  
  792.   
  793.         public void RaisePostBackEvent(string eventArgument)  
  794.         {  
  795.             if (CausesValidation)  
  796.             {  
  797.                 Page.Validate(ValidationGroup);  
  798.             }  
  799.   
  800.             int _currentindex;  
  801.             if (int.TryParse(eventArgument, out _currentindex))  
  802.             {  
  803.                 CurrentIndex = _currentindex;  
  804.             }  
  805.   
  806.             OnClick(EventArgs.Empty);  
  807.         }  
  808.   
  809.         #endregion  
  810.     }  
  811.   
  812.     #endregion  
  813. }  


 

上一篇: linq基本操作 下一篇: Dom操作--跑马灯效果
发表评论
用户名: 匿名