自定义分页控件
来源:互联网 发布:威廉马歇尔 知乎 编辑:程序博客网 时间:2024/05/23 12:30
今天有时间,做了一个简单的自定义分页控件!------
using System;using System.Collections.Generic;using System.ComponentModel;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Web.UI;namespace TextBoxControl{ /// <summary> /// PageList 的摘要说明。 /// </summary> [DefaultProperty("PageList"), ToolboxData("<{0}:MyPageList runat=server></{0}:MyPageList>")] public class PageList : System.Web.UI.WebControls.WebControl, IPostBackEventHandler { public PageList() { this.PageIndex = 0; this.ToCount = 100; this.PageSize = 10; } /// <summary> /// 当前页索引 /// </summary> [Bindable(true), Category("pageInfo"), DefaultValue(0)] public int PageIndex { get { object o = ViewState["PageIndex"]; if (o == null) { return 0; } else { return (int)o; } } set { ViewState["PageIndex"] = value; } } /// <summary> /// 总页数 /// </summary> [Bindable(true)] [Category("Data")] [DefaultValue(0)] private int PageCount { get { return int.Parse(Math.Ceiling(1.0 * ToCount / PageSize).ToString()); } } /// <summary> /// 每页显示条数 /// </summary> [Bindable(true), Category("pageInfo"), DefaultValue(0)] public int PageSize { get { object o = ViewState["PageSize"]; if (o == null) { return 0; } else { return (int)o; } } set { ViewState["PageSize"] = value; } } /// <summary> /// 数据总条数 /// </summary> [Bindable(true), Category("pageInfo"), DefaultValue(0)] public int ToCount { get { object o = ViewState["ToCount"]; if (o == null) { return 0; } else { return (int)o; } } set { ViewState["ToCount"] = value; } } /// <summary> /// 输出HTML /// </summary> /// <param name="output"></param> protected override void Render(HtmlTextWriter output) { output.Write("共:" + this.PageCount.ToString() + "页 "); output.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this, "Home") + "\">首页</a> "); output.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this, "PV") + "\">上一页</a> "); output.Write(getPageList()); output.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this, "NEX") + "\">下一页</a> "); output.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this, "WEI") + "\">尾页</a>"); } /// <summary> /// 页码处理 /// </summary> /// <returns></returns> public string getPageList() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < this.PageCount; i++) { if (i == this.PageIndex) { sb.Append((i + 1).ToString() + " "); } else { sb.Append("<a href=\"javascript:" + Page.GetPostBackEventReference(this, i.ToString()) + "\">" + (i + 1).ToString() + "</a> "); } } return sb.ToString(); } /// <summary> /// 回发事件 /// </summary> /// <param name="eventArgument"></param> public void RaisePostBackEvent(string eventArgument) { if (eventArgument == "Home") { this.PageIndex = 0; } else if (eventArgument == "PV") { this.PageIndex=this.PageIndex == 0 ? 0 : this.PageIndex - 1; } else if (eventArgument == "NEX") { this.PageIndex = this.PageIndex == this.PageCount - 1 ? this.PageCount - 1 : this.PageIndex + 1; } else if (eventArgument == "WEI") { this.PageIndex = this.PageCount-1; } else { try { this.PageIndex = int.Parse(eventArgument.ToString()); } catch { this.PageIndex = 0; } } } }}
- 自定义分页控件
- GridView控件自定义分页
- [GridView控件]自定义分页
- DataGrid自定义分页控件
- GridView控件自定义分页
- VS2005 自定义分页控件
- Repeater控件自定义分页
- DataGrid自定义分页控件
- flex自定义分页控件
- Webform自定义分页控件
- 自定义winform分页控件
- 自定义GridView 分页控件
- 自定义GridView 分页控件
- c#自定义分页控件
- 自定义winform分页控件
- 自定义分页控件
- 自定义的分页控件
- C# 自定义分页控件
- 同步与异步
- 堆排序
- Bash script学习的一写memo
- 按照Json格式读取Mongodb中数据
- Android触摸屏输入系统
- 自定义分页控件
- hibernate4与hibernate3的区别
- try-finally语句
- [Leetcode] Partition List **
- Oracle 11g 新特性 -- Transparent Data Encryption (透明数据加密TDE) 增强 说明
- 23种设计模式之工厂方法模式
- 反编译问题
- bash shell (4) linux bg fg 命令
- linux 内核调试方法