可配置的自定义分页控件

一直以来都觉得分页是麻烦的事情,.NET中虽然有DATAGRID的分页,但用其他形式的列表仍然需要使用到分页,一次一次的写不利于效率及面向对象的方法,用类或用户控件也总觉得怪怪的,用第3方的自己觉得不放心,也不利于自己进行修改,干脆就自己写了一个。
(另外注意:在控件编译时,可以在AssemblyInfo.cs文件中设置控件的标签和名称空间,如:
None.gif using  System.Reflection;
None.gif
using  System.Runtime.CompilerServices;
None.gif
using  System.Web.UI;
None.gif
None.gif[assembly: TagPrefix(
" PublicControls " , " PublicControls " )]   //  自定义控件前缀
第一个参数是名称空间(必须是你的控件类的名称空间),第二个是标签名(可自定义)
记得要加入System.Web.UI;名称空间,另外 将控件类内的
None.gif [DefaultProperty( " Text " ), 
None.gif     ToolboxData(
" <PublicControls:PageNavigation runat=server></PublicControls:PageNavigation> " )]
这句屏蔽掉

所有代码如下:
None.gif using  System;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.ComponentModel;
None.gif
using  System.Collections;
None.gif
using  System.Collections.Specialized;
None.gif
None.gif
namespace  PublicControls
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif     
/**////<summary>
InBlock.gif     
/// PageNavigation 分页导航控件。
ExpandedSubBlockEnd.gif     
///</summary>

InBlock.gif     [DefaultProperty("Text"), 
InBlock.gif     ToolboxData(
"<PublicControls:PageNavigation runat=server></PublicControls:PageNavigation>")]
InBlock.gif     
public class PageNavigation : Control,IPostBackDataHandler,IPostBackEventHandler 
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif         #region预定义
InBlock.gif         
InBlock.gif         
private string _style;
InBlock.gif         
private int _count;
InBlock.gif         
private int _pagesize;
InBlock.gif         
private int _pageindex;
InBlock.gif        
private int _pages;         //页群
InBlock.gif
         private int _currentpages;
InBlock.gif         
private string _first;
InBlock.gif         
private string _pres;
InBlock.gif         
private string _pre;
InBlock.gif         
private string _next;
InBlock.gif         
private string _nexts;
InBlock.gif         
private string _last;
InBlock.gif 
InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///委托页面索引事件
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         public event EventHandler PageIndexChange;
InBlock.gif 
InBlock.gif         
#endregion
InBlock.gif 
InBlock.gif         #region属性
InBlock.gif         
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///相关属性样式字符串属性
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         [Bindable(false), 
InBlock.gif         Category(
"StyleString"), 
InBlock.gif         DefaultValue(
"Align=left")] 
InBlock.gif         
public string StyleString 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _style 
= (string)ViewState["StyleString"];
InBlock.gif                   
return _style;
ExpandedSubBlockEnd.gif              }

InBlock.gif 
InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _style
= value;
InBlock.gif                   ViewState[
"StyleString"= _style;
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///记录总数
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         [Bindable(false), 
InBlock.gif         Category(
"Count"), 
InBlock.gif         DefaultValue(
0)] 
InBlock.gif         
public int Count 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   
if (this.IsNumeric(ViewState["Count"]))
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       _count 
= (int)ViewState["Count"];
ExpandedSubBlockEnd.gif                   }

InBlock.gif                   
return _count;
ExpandedSubBlockEnd.gif              }

InBlock.gif 
InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _count 
= value;
InBlock.gif                   ViewState[
"Count"= _count;
InBlock.gif                   
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///页面大小
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         [Bindable(false), 
InBlock.gif         Category(
"Pagesize"), 
InBlock.gif         DefaultValue(
10)] 
InBlock.gif         
public int Pagesize
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   
InBlock.gif                   
if (this.IsNumeric(ViewState["Pagesize"]))
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       _pagesize 
= (int)ViewState["Pagesize"];
ExpandedSubBlockEnd.gif                   }

InBlock.gif                   
return _pagesize;
ExpandedSubBlockEnd.gif              }

InBlock.gif 
InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _pagesize 
= value;
InBlock.gif                   ViewState[
"Pagesize"= _pagesize;
InBlock.gif                   
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///当前页索引
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         [Bindable(false), 
InBlock.gif         Category(
"Pageindex"), 
InBlock.gif         DefaultValue(
0)] 
InBlock.gif         
public int Pageindex
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   
if (this.IsNumeric(ViewState["Pageindex"]))
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       _pageindex 
= (int)ViewState["Pageindex"];
ExpandedSubBlockEnd.gif                   }

InBlock.gif                   
return _pageindex;
ExpandedSubBlockEnd.gif              }

InBlock.gif 
InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _pageindex 
= value;
InBlock.gif                   ViewState[
"Pageindex"= _pageindex;
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///页群属性
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         public int Pages
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   
if (this.IsNumeric(ViewState["Pages"]))
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       _pages 
= (int)ViewState["Pages"];
ExpandedSubBlockEnd.gif                   }

InBlock.gif                   
return _pages;
ExpandedSubBlockEnd.gif              }

InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _pages 
= value;
InBlock.gif                   ViewState[
"Pages"= _pages;
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///当前页群索引
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         public int CurrentPages
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   
if (this.IsNumeric(ViewState["CurrentPages"]))
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       _currentpages 
= (int)ViewState["CurrentPages"];
ExpandedSubBlockEnd.gif                   }

InBlock.gif                   
return _currentpages;
ExpandedSubBlockEnd.gif              }

InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _currentpages 
= value;
InBlock.gif                   ViewState[
"CurrentPages"= _currentpages;
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///标记样式
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         [Bindable(false), 
InBlock.gif         Category(
"first"), 
InBlock.gif         DefaultValue(
"第一页")] 
InBlock.gif         
public string First 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _first 
= (string)ViewState["First"];
InBlock.gif                   
return _first;
ExpandedSubBlockEnd.gif              }

InBlock.gif 
InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _first 
= value;
InBlock.gif                   ViewState[
"First"= _first;
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///标记样式
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         [Bindable(false), 
InBlock.gif         Category(
"pres"), 
InBlock.gif         DefaultValue(
"前N页")] 
InBlock.gif         
public string Pres 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _pres 
= (string)ViewState["Pres"];
InBlock.gif                   
return _pres;
ExpandedSubBlockEnd.gif              }

InBlock.gif 
InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _pres 
= value;
InBlock.gif                   ViewState[
"Pres"= _pres;
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///标记样式
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         [Bindable(false), 
InBlock.gif         Category(
"pre"), 
InBlock.gif         DefaultValue(
"前一页")] 
InBlock.gif         
public string Pre 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _pre 
= (string)ViewState["Pre"];
InBlock.gif                   
return _pre;
ExpandedSubBlockEnd.gif              }

InBlock.gif 
InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _pre 
= value;
InBlock.gif                   ViewState[
"Pre"= _pre;
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///标记样式
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         [Bindable(false), 
InBlock.gif         Category(
"next"), 
InBlock.gif         DefaultValue(
"后一页")] 
InBlock.gif         
public string Next 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _next 
= (string)ViewState["Next"];
InBlock.gif                   
return _next;
ExpandedSubBlockEnd.gif              }

InBlock.gif 
InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _next 
= value;
InBlock.gif                   ViewState[
"Next"= _next;
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///标记样式
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         [Bindable(false), 
InBlock.gif         Category(
"nexts"), 
InBlock.gif         DefaultValue(
"后N页")] 
InBlock.gif         
public string Nexts 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _nexts 
= (string)ViewState["Nexts"];
InBlock.gif                   
return _nexts;
ExpandedSubBlockEnd.gif              }

InBlock.gif 
InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _nexts 
= value;
InBlock.gif                   ViewState[
"Nexts"= _nexts;
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///标记样式
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         [Bindable(false), 
InBlock.gif         Category(
"last"), 
InBlock.gif         DefaultValue(
"最后一页")] 
InBlock.gif         
public string Last 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
get
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _last 
= (string)ViewState["Last"];
InBlock.gif                   
return _last;
ExpandedSubBlockEnd.gif              }

InBlock.gif              
set
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   _last 
= value;
InBlock.gif                   ViewState[
"Last"= _last;
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
InBlock.gif 
InBlock.gif         
#endregion
InBlock.gif 
InBlock.gif         #region事件
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///当由类实现时,使服务器控件能够处理将窗体发送到服务器时引发的事件。
InBlock.gif         
///</summary>
ExpandedSubBlockEnd.gif         
///<param name="e">所传递的参数</param>

InBlock.gif         public void RaisePostBackEvent(string e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
//当发生回送的时候改变控件当前索引
InBlock.gif
              if(e=="top")
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   Pageindex 
= 0;
InBlock.gif                   CurrentPages 
= 0 ;
ExpandedSubBlockEnd.gif              }

InBlock.gif              
else if(e=="last")
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   Pageindex 
= (Count+Pagesize-1)/Pagesize -1;
InBlock.gif                   
InBlock.gif                   CurrentPages 
= ((Count+Pagesize-1)/Pagesize+Pages-1)/ Pages -1;
InBlock.gif 
InBlock.gif                   
if(Pageindex<0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       Pageindex
=0;
ExpandedSubBlockEnd.gif                   }

InBlock.gif                   
if(CurrentPages<0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       CurrentPages
=0;
ExpandedSubBlockEnd.gif                   }

InBlock.gif                   
ExpandedSubBlockEnd.gif              }

InBlock.gif              
else if(e=="pre")
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   
if(Pageindex>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       Pageindex
--;
InBlock.gif                       
if(Pageindex<CurrentPages*Pages && Pageindex>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                       
dot.gif{
InBlock.gif                            CurrentPages
--;
ExpandedSubBlockEnd.gif                       }

ExpandedSubBlockEnd.gif                   }

ExpandedSubBlockEnd.gif              }

InBlock.gif              
else if(e=="next")
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   
if(Pageindex<(Count+Pagesize-1)/Pagesize -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       Pageindex
++;
InBlock.gif                       
if(Pageindex>(CurrentPages+1)*Pages-1 && Pageindex<Count-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                       
dot.gif{
InBlock.gif                            CurrentPages
++;
ExpandedSubBlockEnd.gif                       }

ExpandedSubBlockEnd.gif                   }

ExpandedSubBlockEnd.gif              }

InBlock.gif              
else if(e=="pres")
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   Pageindex 
-= Pages;
InBlock.gif                   
if(Pageindex<0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       Pageindex 
= 0;
ExpandedSubBlockEnd.gif                   }

InBlock.gif                   
if(Pageindex<CurrentPages*Pages && Pageindex>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       CurrentPages
--;
ExpandedSubBlockEnd.gif                   }

ExpandedSubBlockEnd.gif              }

InBlock.gif              
else if(e=="nexts")
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   Pageindex 
+= Pages;
InBlock.gif                   
if(Pageindex>(Count+Pagesize-1)/Pagesize -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       Pageindex 
= (Count+Pagesize-1)/Pagesize -1;
ExpandedSubBlockEnd.gif                   }

InBlock.gif                   
if(Pageindex>(CurrentPages+1)*Pages-1 && Pageindex<Count-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       CurrentPages
++;
ExpandedSubBlockEnd.gif                   }

ExpandedSubBlockEnd.gif              }

InBlock.gif              
else
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   Pageindex 
= int.Parse(e.ToString());
ExpandedSubBlockEnd.gif              }

InBlock.gif         
InBlock.gif              
//发生回送事件时引发OnPageIndexChange事件
InBlock.gif
              OnPageIndexChange(System.EventArgs.Empty);
ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///当由类实现时,为 ASP.NET 服务器控件处理回发数据。
InBlock.gif         
///</summary>
InBlock.gif         
///<param name="postDataKey">数据集合元素索引</param>
InBlock.gif         
///<param name="values">string 的排序集合</param>
ExpandedSubBlockEnd.gif         
///<returns></returns>

InBlock.gif         public bool LoadPostData(string postDataKey, NameValueCollection values) 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
//Pageindex = Int32.Parse(values[this.UniqueID].Split('|')[0]);
InBlock.gif              
//CurrentPages = Int32.Parse(values[this.UniqueID].Split('|')[1]);
InBlock.gif
              return false;
ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///当由类实现时,用信号要求服务器控件对象通知 ASP.NET 应用程序该控件的状态已更改。
ExpandedSubBlockEnd.gif         
///</summary>

InBlock.gif         public void RaisePostDataChangedEvent() 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///当页面索引改变,触发委托
InBlock.gif         
///</summary>
ExpandedSubBlockEnd.gif         
///<param name="e"></param>

InBlock.gif         protected void OnPageIndexChange(System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{    
InBlock.gif              
//委托给加载控件页的PageIndexChange事件
InBlock.gif
              if (PageIndexChange!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   PageIndexChange(
this,e);
ExpandedSubBlockEnd.gif              }

ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///预呈现
InBlock.gif         
///</summary>
ExpandedSubBlockEnd.gif         
///<param name="e"></param>

InBlock.gif         protected override void OnPreRender(EventArgs e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
ExpandedSubBlockEnd.gif         }

InBlock.gif 
InBlock.gif         
#endregion
InBlock.gif 
InBlock.gif         #region输出
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///将此控件呈现给指定的输出参数。
InBlock.gif         
///</summary>
ExpandedSubBlockEnd.gif         
///<param name="output">要写出到的 HTML 编写器 </param>

InBlock.gif         protected override void Render(HtmlTextWriter output)
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif 
InBlock.gif              
string Pagestring = "";  //定义页码呈现字符串
InBlock.gif
              string Text = null;          //输出主结构字符串变量定义
InBlock.gif
              int NO;
InBlock.gif 
InBlock.gif              
//输出主结构
InBlock.gif
              Text = "<div $style$>";
InBlock.gif              
InBlock.gif              Text 
+="<a href =\"javascript:"+ Page.GetPostBackEventReference(this,"top")+ "\">"+First+"</a>&nbsp;";
InBlock.gif 
InBlock.gif              Text 
+="<a href =\"javascript:"+ Page.GetPostBackEventReference(this,"pres")+ "\">"+Pres+"</a>&nbsp;";
InBlock.gif 
InBlock.gif              Text 
+="<a href =\"javascript:"+ Page.GetPostBackEventReference(this,"pre")+ "\">"+Pre+"</a>&nbsp;";
InBlock.gif 
InBlock.gif              Text 
+="$Pagestring$";
InBlock.gif 
InBlock.gif              Text 
+="<a href =\"javascript:"+ Page.GetPostBackEventReference(this,"next")+ "\">"+Next+"</a>&nbsp;";
InBlock.gif 
InBlock.gif              Text 
+="<a href =\"javascript:"+ Page.GetPostBackEventReference(this,"nexts")+ "\">"+Nexts+"</a>&nbsp;";
InBlock.gif              
InBlock.gif              Text 
+="<a href =\"javascript:"+ Page.GetPostBackEventReference(this,"last")+ "\">"+Last+"</a>&nbsp;";
InBlock.gif 
InBlock.gif              Text 
+="</div>";//<input type = hidden name ="+this.UniqueID+" value = "+this.Pageindex+"|"+this.CurrentPages+">";     
InBlock.gif 
InBlock.gif              
//当页大小小于0时,还原为1,防止预算出现除0错误
InBlock.gif
              if (!(Pagesize>0))
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   Pagesize 
= 1;
ExpandedSubBlockEnd.gif              }

InBlock.gif              
InBlock.gif              
InBlock.gif 
InBlock.gif              
//计算出总页数,并循环输出页码
InBlock.gif
              for (int i = 0;i< Pages ;i++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   
//获得页群内页码
InBlock.gif
                   NO = Pages * CurrentPages + i;
InBlock.gif 
InBlock.gif                   
if(NO<(Count+Pagesize-1)/Pagesize)
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif{
InBlock.gif                       
//判断页码是否为当前页
InBlock.gif
                       if (Pageindex != NO)
ExpandedSubBlockStart.gifContractedSubBlock.gif                       
dot.gif{
InBlock.gif                            Pagestring 
+= "<a href = \"javascript:"+ Page.GetPostBackEventReference(this,NO.ToString())+ "\">"+(NO+1).ToString()+"</a>&nbsp;";
ExpandedSubBlockEnd.gif                       }

InBlock.gif                            
//如果不是,页面部分无连接
InBlock.gif
                       else
ExpandedSubBlockStart.gifContractedSubBlock.gif                       
dot.gif{
InBlock.gif                            Pagestring 
+= (NO+1).ToString()+"&nbsp;";
ExpandedSubBlockEnd.gif                       }

ExpandedSubBlockEnd.gif                   }

ExpandedSubBlockEnd.gif              }

InBlock.gif 
InBlock.gif              
if (!(Pagestring.Trim().Length>0))
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   Pagestring 
= "1";
ExpandedSubBlockEnd.gif              }

InBlock.gif              
InBlock.gif              
//替换对齐属性
InBlock.gif
              Text = Text.Replace("$style$",StyleString);
InBlock.gif            
InBlock.gif              
//替换页码部分
InBlock.gif
              Text = Text.Replace("$Pagestring$",Pagestring);
InBlock.gif              
InBlock.gif 
InBlock.gif              output.Write(Text);
InBlock.gif              
ExpandedSubBlockEnd.gif         }

InBlock.gif         
#endregion
InBlock.gif 
InBlock.gif         #region其他函数
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///判断是否为数字字符串
InBlock.gif         
///</summary>
InBlock.gif         
///<param name="str">需验证的字符串</param>
ExpandedSubBlockEnd.gif         
///<returns>判断结果,符合条件为True,不符合条件为False</returns>

InBlock.gif         public bool IsNumeric(string str)
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
//判断是否为空
InBlock.gif
              if (str == null || str.Length==0
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   
return false
ExpandedSubBlockEnd.gif              }

InBlock.gif              
//循环检查每个字符
InBlock.gif
              foreach(char c in str) 
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif
InBlock.gif                   
if (!Char.IsNumber(c)) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif
InBlock.gif                       
return false
ExpandedSubBlockEnd.gif                   }
 
ExpandedSubBlockEnd.gif              }
 
InBlock.gif              
return true
ExpandedSubBlockEnd.gif         }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**////<summary>
InBlock.gif         
///判断是否为数字字符串
InBlock.gif         
///</summary>
InBlock.gif         
///<param name="obj">需验证的字符串</param>
ExpandedSubBlockEnd.gif         
///<returns>判断结果,符合条件为True,不符合条件为False</returns>

InBlock.gif         public bool IsNumeric(object obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif 
InBlock.gif              obj 
+= "";
InBlock.gif              
string str = obj.ToString();
InBlock.gif              
InBlock.gif              
//判断是否为空
InBlock.gif
              if (str == null || str.Length==0
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif{
InBlock.gif                   
return false
ExpandedSubBlockEnd.gif              }

InBlock.gif              
//循环检查每个字符
InBlock.gif
              foreach(char c in str) 
ExpandedSubBlockStart.gifContractedSubBlock.gif              
dot.gif
InBlock.gif                   
if (!Char.IsNumber(c)) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                   
dot.gif
InBlock.gif                       
return false
ExpandedSubBlockEnd.gif                   }
 
ExpandedSubBlockEnd.gif              }
 
InBlock.gif              
return true
ExpandedSubBlockEnd.gif         }

InBlock.gif 
InBlock.gif         
#endregion
ExpandedSubBlockEnd.gif     }

ExpandedBlockEnd.gif}

None.gif 
None.gif


转载于:https://www.cnblogs.com/rungroo/archive/2006/11/11/557348.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值