文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>SqlPager的再次改进(带数字翻页以及翻页样式设置功能)

SqlPager的再次改进(带数字翻页以及翻页样式设置功能)

时间:2011-01-16  来源:小锋神

  1/**//// <summary>
  2        /// 数字翻页 开始值
  3        /// </summary> 
  4        protected int NumberPageBegin
  5        {
  6            get{return Convert.ToInt32(this.ViewState["_NumberPageBegin"]);}
  7            set{this.ViewState["_NumberPageBegin"]=value;}
  8        }
  9
 10        /**//// <summary>
 11        /// 数字翻页UI
 12        /// </summary>
 13        /// <param name="cell"></param> 
 14        private void BuildNumberUI(TableCell cell)
 15        {
 16            bool isValidPage = (CurrentPageIndex >=0 && CurrentPageIndex <= TotalPages-1);
 17            bool canMoveBack = (CurrentPageIndex>0);
 18            bool canMoveForward = (CurrentPageIndex<TotalPages-1);
 19            bool isFirst=(CurrentPageIndex==0);
 20            bool isLast=(CurrentPageIndex==this.TotalPages-1);
 21            
 22            cell.Controls.Add(new LiteralControl("&nbsp;"));
 23            //第一页
 24            LinkButton linkfirst=new LinkButton();
 25            linkfirst.ID="link_first_0";
 26            //linkfirst.ForeColor = ForeColor;
 27            linkfirst.ToolTip = "第1页";
 28            linkfirst.Text = "1";    
 29            //linkfirst.Attributes.Add("onclick",this.ClientID+"_"+linkfirst.ClientID+".className='"+this.VisitedCssClass+"'");
 30            linkfirst.Click += new EventHandler(linkfirst_Click);
 31            linkfirst.Enabled = !isFirst;
 32//            if(this.CurrentPageIndex==0)
 33//            {
 34//                linkfirst.CssClass=this.VisitedCssClass;
 35//            }
 36//            else
 37//            {
 38                linkfirst.CssClass=this.NotVisitCssClass;
 39//            }
 40            cell.Controls.Add(linkfirst);
 41            cell.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));
 42
 43            //前10页
 44            LinkButton linkprevten=new LinkButton();
 45            int prevten=0;
 46            if(this.CurrentPageIndex%10>0&&this.CurrentPageIndex<this.TotalPages-1)
 47            {
 48                prevten=(this.CurrentPageIndex/10+1)*10;
 49            }
 50            if(this.CurrentPageIndex%10==0)
 51            {
 52                prevten=(this.CurrentPageIndex/10-1)*10;
 53            }
 54            linkprevten.ID="linkprevten_"+prevten.ToString();
 55            //linkprevten.ForeColor = ForeColor;
 56            linkprevten.ToolTip = "前10页";
 57            linkprevten.Text = "";    
 58            linkprevten.Click += new EventHandler(linknumber_Click);
 59            linkprevten.Enabled = (this.CurrentPageIndex-1)<10?false:true;    
 60            cell.Controls.Add(linkprevten);
 61            cell.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));
 62
 63            //中间的数字
 64            int counter=0;//计数器
 65            if((this.CurrentPageIndex+1)%10==0)
 66            {
 67                this.NumberPageBegin=this.CurrentPageIndex+1;
 68            }
 69            else if((this.CurrentPageIndex+1)%10==1)
 70            {
 71                if(this.CurrentPageIndex>=10)
 72                {
 73                    this.NumberPageBegin=this.CurrentPageIndex-10;
 74                }
 75                else
 76                {
 77                    this.NumberPageBegin=0;
 78                }
 79            }
 80            else
 81            {
 82                if(this.CurrentPageIndex/10>0&&this.CurrentPageIndex/10<this.TotalPages/10)
 83                {
 84                    this.NumberPageBegin=(this.CurrentPageIndex/10)*10;
 85                }
 86                if(this.CurrentPageIndex/10>0&&this.CurrentPageIndex/10==this.TotalPages/10)
 87                {
 88                    this.NumberPageBegin=(this.CurrentPageIndex/10)*10;
 89                }
 90            }
 91            for(int i=this.NumberPageBegin;i<this.TotalPages&&counter<10;i++)
 92            {
 93                LinkButton midLink=new LinkButton();
 94                midLink.ID="midLnk_"+i.ToString();
 95                midLink.Text=(i+1).ToString();
 96                midLink.Click += new EventHandler(linknumber_Click);
 97                //midLink.ForeColor = ForeColor;
 98                midLink.ToolTip = "第"+(i+1).ToString()+"页";
 99                //midLink.Attributes.Add("onfocus",this.ClientID+"_"+midLink.ClientID+".className='"+this.VisitedCssClass+"'");
100                //midLink.Attributes.Add("class",this.VisitedCssClass);
101                
102                    //this.ClientID+"_"+midLink.ClientID+".className='"+this.VisitedCssClass+"'";
103
104//                if(this.CurrentPageIndex==NumberPageBegin)
105//                {
106//                    midLink.CssClass=this.VisitedCssClass;
107//                }
108//                else
109//                {
110                    midLink.CssClass=this.NotVisitCssClass;
111//                }
112//                if(isFirst||isLast)
113//                {
114//                    midLink.Enabled=false;
115//                }
116//                else
117//                {
118//                    midLink.Enabled=true;
119//                }
120                //midLink.Enabled=!isFirst||!isLast;
121                cell.Controls.Add(midLink);
122                cell.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));
123                counter++;
124            }
125            
126            //后10页
127            LinkButton linknextten=new LinkButton();
128            int nextten=0;
129            if(this.CurrentPageIndex%10==0&&this.CurrentPageIndex>0)
130            {
131                nextten=(this.CurrentPageIndex/10-1)*10+9;
132            }
133            if(this.CurrentPageIndex%10==0&&this.CurrentPageIndex==0)
134            {
135                nextten=(this.CurrentPageIndex/10)*10+9;
136            }
137            if(this.CurrentPageIndex%10>0)
138            {
139                nextten=(this.CurrentPageIndex/10+1)*10+9;
140            }
141            linknextten.ID="linknextten_"+nextten.ToString();
142            //linknextten.ForeColor = ForeColor;
143            linknextten.ToolTip = "后10页";
144            linknextten.Text = "";    
145            linknextten.Click += new EventHandler(linknumber_Click);
146            linknextten.Enabled = nextten>this.TotalPages?false:true;    
147            cell.Controls.Add(linknextten);
148            cell.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));
149
150            //最后一页
151            LinkButton linklast=new LinkButton();
152            linklast.ID="linkfirst_"+(this.TotalPages-1).ToString();
153            //linklast.ForeColor = ForeColor;
154            linklast.ToolTip = "第"+this.TotalPages.ToString()+"页";
155            linklast.Text = this.TotalPages.ToString();
156            //linklast.Attributes.Keys["href"]+=this.ClientID+"_"+linklast.ClientID+".className='"+this.VisitedCssClass+"'";
157            linklast.Click += new EventHandler(linklast_Click);
158            linklast.Enabled = !isLast;
159//            if(this.CurrentPageIndex==this.TotalPages-1)
160//            {
161//                linklast.CssClass=this.VisitedCssClass;
162//            }
163//            else
164//            {
165                linklast.CssClass=this.NotVisitCssClass;
166//            }
167            cell.Controls.Add(linklast);
168            
169
170        }

数字翻页的事件

 1/**//// <summary>
 2        /// 数字跳转
 3        /// </summary>
 4        /// <param name="sender"></param>
 5        /// <param name="e"></param> 
 6        private void linknumber_Click(object sender, EventArgs e)
 7        {                        
 8            
 9            LinkButton link=(LinkButton)sender;            
10            string linkID=link.ID;
11            int charIndex=linkID.IndexOf("_")+1;
12            int pageID=Convert.ToInt32(linkID.Substring(charIndex,linkID.Length-charIndex));             
13            //this.ChangeLnkBtnCssClass(link);
14            
15            link.CssClass=this.VisitedCssClass;
16            //((LinkButton)sender).CssClass=this.VisitedCssClass;
17            
18            GoToPage(pageID);
19        }


如还有不清楚之处可以联系本人!

源代码下载:LJHSqlPager.rar (本人测试调试了一天,希望大家看后多多指教!)

排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载