一个自认为貌似Baidu,Google的翻页导航控件

本文介绍了一款自定义的无源虚拟分页控件,该控件支持自定义每页显示记录数、页码显示数量等,并提供了一个示例存储过程用于获取分页数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    呵呵!今天午觉没睡好,感觉太热了,睡了一下子就热醒了,同事们都不吹空调了,没办法!
现在已经是上班时间了,但一点也不想做事,再加上没睡好,头晕晕的,跑到洗手间用冷水洗
一把脸,回到办公桌前,就想到先写篇BLOG吧,昨天写了一个分页控件,把它写到自己的BLOG
上去,呵呵!其实这个控件之前是我同事写的,昨天闲得无聊,就想到把同事那个控件改进一下
吧,我觉得搞得太复杂了(按钮太多、、、,我自认为不需要那些东东)
  我同事把这个控件称之为“无源虚拟分页控件”因为它是不需要数据源的,只起到虚拟选择页
号与定位的作用,只需要指定其TotalRecord(记录总数)就可以帮你虚拟分页了.
  控件的按钮支持文字和图片俩种格式,可以设定其版页最大显示数,每页显示记录数,以及鼠标
放在按钮上的提示信息.
  由于是无源虚拟分页,所以控件必须给定TotalRecord(记录总数)以及实现ChangePageClick事件
那么记录的总数怎么出来呢,那当然是通过存储过程来取得了,这个存储过程必须是每次取得的数据
是当前展示所需要的(也就是说取当前页的记录),如果一股脑儿把所有满足条件的数据全取出来
那根本就没有意义了,所以呢,要实现分页这个存储过程也是很重要的。
  下面是我做DEMO的存储过程
None.gifset ANSI_NULLS ON
None.gif
set QUOTED_IDENTIFIER ON
None.gif
go
None.gif
None.gif
-- =============================================
None.gif--
 Author:        <不懂>
None.gif--
 Create date: <2006-11-8>
None.gif--
 Description:    <分页存储过程>
None.gif--
 =============================================
None.gif
ALTER PROCEDURE [dbo].[P_PageRecord]
None.gif(
@intPageSize int=10,@intPageNum int=1,@strWhere nvarchar(200))
None.gif
AS
None.gif
BEGIN
None.gif    
SET NOCOUNT ON;
None.gif
None.gif    
if(@intPageSize<2 or @intPageSize>100)
None.gif        
set @intPageSize=10
None.gif    
if(@intPageNum<1)
None.gif        
set @intPageNum=1;
None.gif    
WITH Search(OrderID,CustomerID,EmployeeID,OrderDate,RequiredDate,ShippedDate , ShipVia ,Freight ,ShipName,RowNum)
None.gif           
as
None.gif              (
None.gif              
select OrderID ,
None.gif                     CustomerID,
None.gif                     EmployeeID ,
None.gif                     OrderDate,
None.gif                     RequiredDate,
None.gif                     ShippedDate ,
None.gif                     ShipVia ,
None.gif                     Freight ,
None.gif                     ShipName,
None.gif                     ROW_NUMBER() 
over (order by OrderID DESCas RowNum
None.gif              
from Orders where ShipAddress like N'%'+@strWhere+N'%'
None.gif              )
None.gif
None.gif    
SELECT OrderID,CustomerID,EmployeeID,OrderDate,RequiredDate,ShippedDate , ShipVia ,Freight ,ShipName,(select count(*from Search) as Rows from Search
None.gif    
where RowNum>@intPageSize*(@intPageNum-1and RowNum<=@intPageSize*@intPageNum
None.gif   
SET NOCOUNT OFF;
None.gif   
return @@ERROR
None.gif
END


   这个分页控件是个完全自定义的控件没有UI的,继承于WebControl,为了响应事件还得继承IPostBackEventHandler,下面就是完整的实现代码。

 

None.gifusing System;
None.gif
using System.Collections.Generic;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.HtmlControls;
None.gif
using System.ComponentModel;
None.gif
using System.Text;
None.gif
None.gif[assembly: TagPrefix(
"SmbComponent","BG")]
None.gif
namespace SmbComponent
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 作者:不懂
InBlock.gif    
/// 日期:2006-11-8
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    [DefaultProperty("TotalRecord"), DefaultEvent("ChangePageClick"), ToolboxData("<{0}:PageList runat=server></{0}:PageList>")]
InBlock.gif    
public class PageList:WebControl,IPostBackEventHandler
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
公用变量#region 公用变量
InBlock.gif        
private int _iTotalRecord = 0;//记录总数
InBlock.gif
        private int _iPageSize = 10;//页码大小
InBlock.gif
        private int _iItemSize = 10;//页规格
InBlock.gif
        private int _iCurrentPage = 1;//当前页码
InBlock.gif
        private int _iTotalPage = 0;//总页数
ExpandedSubBlockEnd.gif
        #endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
导航图片路径及相关变量#region 导航图片路径及相关变量
InBlock.gif        
private string _strPrevICON = string.Empty;//上一页图片
InBlock.gif
        private string _strNextICON = string.Empty;//下一页图片
InBlock.gif
        
InBlock.gif
InBlock.gif        
private string _strCurrColor = "#CC0000";//当前选择页码颜色
InBlock.gif
        private string _strLinkColor = "#0000C0";//字休颜色
InBlock.gif
        private string _strCssClass = "none";//控件样式表
InBlock.gif

InBlock.gif        
private string _strPrevTitle = "上一页";//上一页按钮显示的文字
InBlock.gif
        private string _strNextTitle = "下一页";//下一页按钮显示的文字
InBlock.gif

InBlock.gif        
private string _strPrevMessage = "";//上一页的提示信息
InBlock.gif
        private string _strNextMessage = "";//下一页的提示信息
InBlock.gif

InBlock.gif        
private string _strPageNOMessage = "点击跳转到第:";//鼠标放在按钮上显示的文字
InBlock.gif

InBlock.gif        
private PageButtonStyle pageButtonStyel = PageButtonStyle.Text;
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
枚举#region 枚举
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 分页控件按钮类型
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public enum PageButtonStyle
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Text,           
// 文字
InBlock.gif
            Picture         // 图片
ExpandedSubBlockEnd.gif
        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
属性#region 属性
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
总记录数#region 总记录数
InBlock.gif        [Description(
"记录总数"),Bindable(true),Category("Appearance"),DefaultValue(0)]
InBlock.gif        
public int TotalRecord
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _iTotalRecord;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
foreach (char c in System.Convert.ToString(value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (!Char.IsNumber(c))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        _iTotalRecord 
= 0;
InBlock.gif                        
break;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                _iTotalRecord 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
页码大小#region 页码大小
InBlock.gif        [Description(
"每页记录数"),Bindable(true),Category("Appearance"),DefaultValue(10)]
InBlock.gif        
public int PageSize
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _iPageSize; }
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (value == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _iPageSize 
= 10;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _iPageSize 
= 10;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
页规格#region 页规格
InBlock.gif        [Description(
"一次显示多少页"),Bindable(true),Category("Appearance"),DefaultValue(10)]
InBlock.gif        
public int ItemSize
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _iItemSize;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (value <= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _iItemSize 
= 10;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _iItemSize 
= value;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
当前页码#region 当前页码
InBlock.gif        [Description(
"当前选择页码"),Bindable(true),Category("Appearance"),DefaultValue(1)]
InBlock.gif        
public int CurrentPage
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _iCurrentPage;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (value <= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _iCurrentPage 
= 1;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _iCurrentPage 
= value;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
总页数#region 总页数
InBlock.gif        [
InBlock.gif        Description(
"总的页数"),
InBlock.gif        Bindable(
true),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
0)
InBlock.gif        ]
InBlock.gif        
public int TotalPage
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _iTotalPage; }
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
页码颜色#region 页码颜色
InBlock.gif        [
InBlock.gif           Description(
"页码颜色"),
InBlock.gif           Bindable(
true),
InBlock.gif           Category(
"Appearance"),
InBlock.gif           DefaultValue(
"Navy")
InBlock.gif        ]
InBlock.gif        
private string LinkColor
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _strLinkColor; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _strLinkColor = value; }
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
当前选择页码颜色#region 当前选择页码颜色
InBlock.gif        [
InBlock.gif           Description(
"当前选择页码颜色"),
InBlock.gif           Bindable(
true),
InBlock.gif           Category(
"Appearance"),
InBlock.gif           DefaultValue(
"#EEEEEE")
InBlock.gif        ]
InBlock.gif        
private string CurrentPageColor
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _strCurrColor; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _strCurrColor = value; }
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
当前控件样式表#region 当前控件样式表
InBlock.gif        [
InBlock.gif           Description(
"当前控件样式表"),
InBlock.gif           Bindable(
true),
InBlock.gif           Category(
"Appearance"),
InBlock.gif           DefaultValue(
"none")
InBlock.gif        ]
InBlock.gif        
private string ControlCssClass
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _strCssClass; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _strCssClass = value; }
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
上一页图片#region 上一页图片
InBlock.gif        [
InBlock.gif           Description(
"上一页图片"),
InBlock.gif           Bindable(
true),
InBlock.gif           Category(
"Appearance"),
InBlock.gif           DefaultValue(
"")
InBlock.gif        ]
InBlock.gif        
public string PrevICON
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _strPrevICON; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _strPrevICON = value; }
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
下一页图片#region 下一页图片
InBlock.gif        [
InBlock.gif           Description(
"下一页图片"),
InBlock.gif           Bindable(
true),
InBlock.gif           Category(
"Appearance"),
InBlock.gif           DefaultValue(
"")
InBlock.gif        ]
InBlock.gif        
public string NextICON
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _strNextICON; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _strNextICON = value; }
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
上一页按钮的文字#region 上一页按钮的文字
InBlock.gif        [
InBlock.gif          Description(
"上一页按钮文字"),
InBlock.gif          Bindable(
true),
InBlock.gif          Category(
"Appearance"),
InBlock.gif          DefaultValue(
"上一页")
InBlock.gif       ]
InBlock.gif        
public string PrevTitle
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _strPrevTitle;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _strPrevTitle 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
下一页按钮的文字#region 下一页按钮的文字
InBlock.gif        [
InBlock.gif          Description(
"下一页按钮文字"),
InBlock.gif          Bindable(
true),
InBlock.gif          Category(
"Appearance"),
InBlock.gif          DefaultValue(
"下一页")]
InBlock.gif        
public string NextTitle
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _strNextTitle;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _strNextTitle 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
上一页的提示信息#region 上一页的提示信息
InBlock.gif        [
InBlock.gif           Description(
"上一页鼠标放上显示信息"),
InBlock.gif           Bindable(
true),
InBlock.gif           Category(
"Appearance"),
InBlock.gif           DefaultValue(
"")
InBlock.gif        ]
InBlock.gif        
public string PrevMessage
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _strPrevMessage; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _strPrevMessage = value; }
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
下一页的提示信息#region 下一页的提示信息
InBlock.gif        [
InBlock.gif           Description(
"下一页鼠标放上显示信息"),
InBlock.gif           Bindable(
true),
InBlock.gif           Category(
"Appearance"),
InBlock.gif           DefaultValue(
"")
InBlock.gif        ]
InBlock.gif        
public string NextMessage
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _strNextMessage; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _strNextMessage = value; }
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
数字导航提示信息#region 数字导航提示信息
InBlock.gif        [
InBlock.gif          Description(
"数字导般鼠标放上显示信息"),
InBlock.gif          Bindable(
true),
InBlock.gif          Category(
"Appearance"),
InBlock.gif          DefaultValue(
"")
InBlock.gif       ]
InBlock.gif        
public string PageNOMessage
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _strPageNOMessage; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _strPageNOMessage = value; }
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
分页控件按钮类型#region 分页控件按钮类型
InBlock.gif        [
InBlock.gif           Description(
"分页控件按钮类型"),
InBlock.gif           Bindable(
true),
InBlock.gif           Category(
"Appearance"),
InBlock.gif           DefaultValue(
0)
InBlock.gif        ]
InBlock.gif        
public PageButtonStyle ButtonStyle
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn pageButtonStyel; }
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                pageButtonStyel 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
定义事件#region 定义事件
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 定义选择页委托
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sender">事件对象</param>
InBlock.gif        
/// <param name="e">事件参数</param>
InBlock.gif        
/// 作者:不懂
ExpandedSubBlockEnd.gif        
/// 日期:2006-11-8

InBlock.gif        public delegate void PageChangeEventHandler(object sender, EventArgs e);
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 定义事件
InBlock.gif        
/// </summary>
InBlock.gif        
/// 作者:不懂
ExpandedSubBlockEnd.gif        
/// 日期:2006-11-8

InBlock.gif        public event PageChangeEventHandler ChangePageClick;
InBlock.gif
InBlock.gif        
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
构造涵数#region 构造涵数
InBlock.gif        
public PageList()
InBlock.gif            : 
base(HtmlTextWriterTag.Div)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{ }
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
重写的方法#region 重写的方法
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 定义当前控件的DIV样式
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="writer"></param>
InBlock.gif        
/// 作者:不懂
ExpandedSubBlockEnd.gif        
/// 日期:2006-11-8

InBlock.gif        protected override void AddAttributesToRender(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            writer.AddStyleAttribute(
"White-space""nowrap");
InBlock.gif            writer.AddStyleAttribute(
"Padding-Top""2px");
InBlock.gif            writer.AddStyleAttribute(
"Padding-Bottom""2px");
InBlock.gif            writer.AddStyleAttribute(
"Width", Width.ToString());
InBlock.gif            writer.AddStyleAttribute(
"Height", Height.ToString());
InBlock.gif            
base.AddAttributesToRender(writer);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 客户端回发处理事件
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="eventArgument"></param>
InBlock.gif        
/// 作者:不懂ExpandedSubBlockEnd.gif        /// 日期:2006-11-8

InBlock.gif        public void RaisePostBackEvent(string eventArgument)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int PageIndex = int.Parse(eventArgument);
InBlock.gif            
this._iCurrentPage = PageIndex;
InBlock.gif            OnPageChangeClick(
new EventArgs());
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 响应页码选择的事件方法
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="e"></param>
InBlock.gif        
/// 作者:不懂
ExpandedSubBlockEnd.gif        
/// 日期:2006-11-8

InBlock.gif        protected virtual void OnPageChangeClick(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (ChangePageClick != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ChangePageClick(
this, e);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 为控件的呈现指定输出参数
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="writer"></param>
InBlock.gif        
/// 作者:不懂
ExpandedSubBlockEnd.gif        
/// 日期:2006-11-8

InBlock.gif        public override void RenderControl(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (TotalRecord > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                PageCurAndTotal(writer);
InBlock.gif                PageBegin(writer);
InBlock.gif                PageItemList(writer);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
base.RenderControl(writer);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
私有方法#region 私有方法
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 输出"当前页/总页数"
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="output"></param>
InBlock.gif        
/// 作者:不懂
ExpandedSubBlockEnd.gif        
/// 日期:2006-11-8

InBlock.gif        private void PageCurAndTotal(HtmlTextWriter output)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this._iTotalPage = (this.TotalRecord % this.PageSize) == 0 ? (this.TotalRecord / this.PageSize) : (this.TotalRecord / this.PageSize) + 1;
InBlock.gif            output.Write(CurrentPage.ToString() 
+ "/" + TotalPage.ToString());
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void PageBegin(HtmlTextWriter output)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string strBegin = string.Empty;
InBlock.gif            
string strPrev;
InBlock.gif            
if (this.ButtonStyle == PageButtonStyle.Text)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                strPrev 
= this.PrevTitle;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                strPrev 
= "<img src='" + this.PrevICON + "' alt='" + this.PrevMessage + "'/>";
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
if (CurrentPage > 1)
InBlock.gif                strBegin 
= "<a id=\"" + this.UniqueID + "\" title='" + this.PrevMessage + "' href=\"javascript:" + Page.GetPostBackEventReference(this, (CurrentPage - 1).ToString()) + "\">" + strPrev + "</a>";
InBlock.gif            output.Write(strBegin);        
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void PageItemList(HtmlTextWriter output)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string strPageIndexColor = string.Empty;
InBlock.gif            
string strPageItemList = string.Empty;
InBlock.gif
InBlock.gif            
int MaxItem = this.ItemSize / 2 + (CurrentPage - 1> TotalPage ? TotalPage : this.ItemSize / 2 + (CurrentPage - 1);
InBlock.gif            
int MinItem = MaxItem <= this.ItemSize ? 1 : (MaxItem - ItemSize) + 1;
InBlock.gif            
for (int item = MinItem; item <= MaxItem; item++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                strPageIndexColor 
= item == CurrentPage ? this.CurrentPageColor : this.LinkColor;
InBlock.gif                
if(item ==CurrentPage)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    strPageItemList 
+= " <font color='" + strPageIndexColor + "'>" + item.ToString() + "</font>";
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                strPageItemList 
+=" <a id=\""+this.UniqueID+"\" title='"+PageNOMessage+item.ToString()+"页 ' href=\"javascript:"+Page.GetPostBackEventReference(this,item.ToString())+"\"<font color="+strPageIndexColor+">"+item.ToString()+"</font></a>" ;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            output.Write(strPageItemList);
InBlock.gif
InBlock.gif            
//输出尾部
InBlock.gif
            string strEnd = string.Empty;
InBlock.gif            
string strNext;
InBlock.gif            
if (this.ButtonStyle == PageButtonStyle.Text)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                strNext 
= this.NextTitle;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                strNext 
= "<img src='" + this.NextICON + "' alt='" + this.NextMessage + "'/>";
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if (TotalPage>1 && MaxItem<TotalPage)
InBlock.gif                strEnd 
= " <a id=\"" + this.UniqueID + "\" title='" + this.NextMessage + "' href=\"javascript:" + Page.GetPostBackEventReference(this, (CurrentPage + 1).ToString()) + "\">" + strNext + "</a>";
InBlock.gif            output.Write(strEnd);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/sunming0905/archive/2006/11/09/555362.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值