特性:
、支持datagrid,datalist等分种数据显示控件,理论上只要有datasource的控件都可以
、支持url方式分页,url分页的每一页都可以被搜索引擎搜到,并且支持url重写
、控件样式可自定义
、封装完全,使用过程序只需写一行代码
复制代码 代码如下:
/******************************************************************
** 文件名:Pager.cs
** 创建人:杨响武
** 日 期:2005年7月27日
** 修改人:
** 日 期:
** 描 述:
**
**----------------------------------------------------------------
******************************************************************/
using System;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web;
using System.Web.UI;
using System.Text.RegularExpressions;
namespace MyCompany.Controls
{
/// <summary>
/// 分页控件
/// </summary>
public class Pager : Label, INamingContainer
{
#region 成员变量和构造函数
HttpContext context = HttpContext.Current;
Label countLabel;
HyperLink previousButton;
HyperLink nextButton;
HyperLink firstButton;
HyperLink lastButton;
HyperLink[] pagingLinkButtons;
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
protected override void CreateChildControls()
{
Controls.Clear();
AddCountLabel();
AddPageButtons();
AddPreviousNextHyperLinks();
AddFirstLastHyperLinks();
}
#endregion
#region 呈现方法
protected override void Render(HtmlTextWriter writer)
{
// 修改总页数小于等于1的时候不呈现任何控件
// int totalPages = CalculateTotalPages();
//
// if (totalPages <= 1)
// return;
AddAttributesToRender(writer);
writer.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClass, false);
RenderCountLabel(writer);
RenderFirst(writer);
RenderPrevious(writer);
RenderPagingButtons(writer);
RenderNext(writer);
RenderLast(writer);
}
void RenderCountLabel(HtmlTextWriter writer)
{
countLabel.RenderControl(writer);
LiteralControl l = new LiteralControl(" ");
l.RenderControl(writer);
}
void RenderFirst (HtmlTextWriter writer)
{
firstButton.RenderControl(writer);
LiteralControl l = new LiteralControl(" ");
l.RenderControl(writer);
}
void RenderLast (HtmlTextWriter writer)
{
lastButton.RenderControl(writer);
LiteralControl l = new LiteralControl(" ");
l.RenderControl(writer);
}
void RenderPrevious (HtmlTextWriter writer)
{
previousButton.RenderControl(writer);
LiteralControl l = new LiteralControl(" ");
l.RenderControl(writer);
}
void RenderNext(HtmlTextWriter writer)
{
nextButton.RenderControl(writer);
LiteralControl l = new LiteralControl(" ");
l.RenderControl(writer);
}
private void RenderButtonRange(int start, int end, HtmlTextWriter writer)
{
for (int i = start; i < end; i++)
{
if (PageIndex == i)
{
Literal l = new Literal();
l.Text = "<font color =red>" + (i + 1).ToString() + "</font>";
l.RenderControl(writer);
}
else
{
pagingLinkButtons.RenderControl(writer);
}
if (i < (end - 1))
writer.Write(" ");
}
LiteralControl l1 = new LiteralControl(" ");
l1.RenderControl(writer);
}
private void RenderPagingButtons(HtmlTextWriter writer)
{
int totalPages;
totalPages = CalculateTotalPages();
if (totalPages <= 10)
{
RenderButtonRange(0, totalPages, writer);
}
else
{
int lowerBound = (PageIndex - 4);
int upperBount = (PageIndex + 6);
if (lowerBound <= 0)
lowerBound = 0;
if (PageIndex <= 4)
RenderButtonRange(0, 10, writer);
else if (PageIndex < (totalPages - 5))
RenderButtonRange(lowerBound, (PageIndex + 6), writer);
else if (PageIndex >= (totalPages - 5))
RenderButtonRange((totalPages - 10), totalPages, writer);
}
}
#endregion
#region 控件树方法
/// <summary>
/// 信息标签
/// </summary>
void AddCountLabel()
{
countLabel = new Label();
countLabel.ID = "countLabel";
countLabel.Text = string.Format(text, CalculateTotalPages().ToString("n0"));
Controls.Add(countLabel);
}
private void AddPageButtons()
{
pagingLinkButtons = new HyperLink[CalculateTotalPages()];
for (int i = 0; i < pagingLinkButtons.Length; i++)
{
pagingLinkButtons = new HyperLink();
pagingLinkButtons.EnableViewState = false;
pagingLinkButtons.Text = (i + 1).ToString();
pagingLinkButtons.ID = i.ToString();
pagingLinkButtons.CssClass = linkCss;
pagingLinkButtons.NavigateUrl = GetHrefString(i);
Controls.Add(pagingLinkButtons);
}
}
/// <summary>
/// 首页末页
/// </summary>
void AddFirstLastHyperLinks()
{
firstButton = new HyperLink();
firstButton.ID = "First";
firstButton.Text = "首页";
if(PageIndex != 0 && CalculateTotalPages() > 0)
{
firstButton.NavigateUrl = GetHrefString(0);
}
else
{
firstButton.Enabled = false;
}
Controls.Add(firstButton);
lastButton = new HyperLink();
lastButton.ID = "Last";
lastButton.Text = "末页";
if(PageIndex != CalculateTotalPages() - 1)
{
lastButton.NavigateUrl = GetHrefString(CalculateTotalPages() - 1);
}
else
{
lastButton.Enabled = false;
}
Controls.Add(lastButton);
}
/// <summary>
/// 上一页下一页
/// </summary>
void AddPreviousNextHyperLinks()
{
previousButton = new HyperLink();
previousButton.ID = "Prev";
previousButton.Text = "上一页";
if (HasPrevious)
{
previousButton.NavigateUrl = GetHrefString(PageIndex - 1);
}
else
{
previousButton.Enabled = false;
}
Controls.Add(previousButton);
nextButton = new HyperLink();
nextButton.ID = "Next";
nextButton.Text = "下一页";
if(HasNext)
{
nextButton.NavigateUrl = GetHrefString(PageIndex + 1);
}
else
{
nextButton.Enabled = false;
}
Controls.Add(nextButton);
}
#endregion
#region 私有属性
private bool HasPrevious
{
get
{
if (PageIndex > 0)
return true;
return false;
}
}
private bool HasNext
{
get
{
if (PageIndex + 1 < CalculateTotalPages() )
return true;
return false;
}
}
#endregion
#region 帮助方法和公共属性
/// <summary>
/// 获取分页导航按钮的超链接字符串
/// </summary>
/// <param name="pageIndex">该分页按钮相对应的页索引</param>
/// <returns>分页导航按钮的超链接字符串</returns>
private string GetHrefString(int pageIndex)
{
string url = Page.Request.RawUrl;
if (Regex.IsMatch(url, @"(\d+).shtml", RegexOptions.IgnoreCase))
{
url = Regex.Replace(url, @"(\d+).shtml", pageIndex + ".shtml");
}
if (Regex.IsMatch(url, @"PageIndex=(\d+)", RegexOptions.IgnoreCase))
{
url = Regex.Replace(url, @"PageIndex=(\d+)", "PageIndex=" + pageIndex.ToString());
}
return Page.Server.UrlPathEncode(url);
}
public int CalculateTotalPages()
{
int totalPagesAvailable;
if (TotalRecords == 0)
return 0;
totalPagesAvailable = TotalRecords / PageSize;
if ((TotalRecords % PageSize) > 0)
totalPagesAvailable++;
return totalPagesAvailable;
}
/// <summary>
/// 当前页
/// </summary>
public int PageIndex
{
get
{
int _pageIndex = 0;
if ((!Page.IsPostBack) && (context.PageIndex > 0))
_pageIndex = context.PageIndex;
else
_pageIndex = Convert.ToInt32(ViewState["PageIndex"]);
if (_pageIndex < 0)
return 0;
else
{
if (_pageIndex > CalculateTotalPages()-1)
return CalculateTotalPages()-1;
else
return _pageIndex;
}
}
set
{
ViewState["PageIndex"] = value;
}
}
/// <summary>
/// 每页记录数
/// </summary>
public int PageSize
{
get
{
int pageSize = Convert.ToInt32(ViewState["PageSize"]);
if (pageSize == 0)
{
return 10;
}
return pageSize;
}
set
{
ViewState["PageSize"] = value;
}
}
/// <summary>
/// 总记录数
/// </summary>
public int TotalRecords
{
get
{
return Convert.ToInt32(ViewState["TotalRecords"]);
}
set
{
ViewState["TotalRecords"] = value;
}
}
private string text = "共{0}页";
private string linkCss = "";
/// <summary>
/// 链接样式
/// </summary>
public string LinkCss
{
get { return linkCss; }
set { linkCss = value;}
}
private string textCss = "";
/// <summary>
/// 文字样式
/// </summary>
public string TextCss
{
get { return textCss; }
set { textCss = value;}
}
public string TextFormat
{
get
{
return text;
}
set
{
text = value;
}
}
#endregion
}
}
在页面上只需要向下面这样写:
复制代码 代码如下:
<%@ Control Language="c#" %>
<%@ Register TagPrefix="Anchor" Namespace="MyCompany.Controls" Assembly="MyCompany.Controls" %>
<ANCHOR:PAGER id="Pager1" runat="server"></ANCHOR:PAGER>
ASP.Net,分页控件
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
- 群星《继续微笑致敬许冠杰》[低速原抓WAV+CUE]
- 潘秀琼.2003-国语难忘金曲珍藏集【皇星全音】【WAV+CUE】
- 林东松.1997-2039玫瑰事件【宝丽金】【WAV+CUE】
- 谭咏麟.2022-倾·听【环球】【WAV+CUE】
- 4complete《丛生》[320K/MP3][85.26MB]
- 4complete《丛生》[FLAC/分轨][218.01MB]
- 羽泉《给未来的你&天黑天亮》[WAV+CUE][968M]
- 庄心妍《我也许在等候》[低速原抓WAV+CUE]
- 王雅洁《小调歌后2》[原抓WAV+CUE]
- 中国武警男声合唱团《辉煌之声1天路》[DTS-WAV分轨]
- 紫薇《旧曲新韵》[320K/MP3][175.29MB]
- 紫薇《旧曲新韵》[FLAC/分轨][550.18MB]
- 周深《反深代词》[先听版][320K/MP3][72.71MB]
- 李佳薇.2024-会发光的【黑籁音乐】【FLAC分轨】
- 后弦.2012-很有爱【天浩盛世】【WAV+CUE】