- 浏览: 232256 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
njmnjx:
humors221 写道这篇文章还不错,不过有一个小问题,就是 ...
html判断页面加载完毕 -
donkey526485268:
httpModules应用 -
humors221:
这篇文章还不错,不过有一个小问题,就是setInterval( ...
html判断页面加载完毕 -
小昭WBCA:
[/ code]
jquery判断子元素是否存在
最近做项目见到别人写的一个分页控件不错,记录一下关于路径的问题。
一、解决方案
二、添加类库项目test
三、添加引用System.Web
四、test下添加类文件Pagination.cs
五、test下添加样式文件Pagination.css(右键此文件--属性--生成操作--嵌入的资源)
六、Pagination.cs文件下添加如下内容
七、注:类文件的命名空间任意,嵌入资源路径要注意。
八、结构图如下:
九、vs工具箱--添加选项卡--选择荐--浏览(上面生成的dll文件)--确定完成。
或者:将dll文件拖曳入vs工具箱中即可。
十、拖曳使用控件。
十一、例句如下:
十二、效果图:
十三、附件:编译完成可用的 dll文件
一、解决方案
二、添加类库项目test
三、添加引用System.Web
四、test下添加类文件Pagination.cs
五、test下添加样式文件Pagination.css(右键此文件--属性--生成操作--嵌入的资源)
六、Pagination.cs文件下添加如下内容
using System; using System.Text.RegularExpressions; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; //这里是引用嵌入资源的路径 项目名称.文件夹.文件名 [assembly: WebResource("test.css.Pagination.css", "css")] namespace Common //命名空间任意 { public class Pagination : WebControl, INamingContainer, IPostBackEventHandler { public enum PaginationMode { Get, Post } #region = 1 Count = /// <summary> /// 内容总条数 /// </summary> public int Count { get { return ViewState["Count"] != null ? (int)ViewState["Count"] : 0; } set { ViewState["Count"] = value; } } #endregion #region = 2 PageNum = /// <summary> /// 每页内容数 /// </summary> public int PageNum { get { return ViewState["PageNum"] != null ? (int)ViewState["PageNum"] : 20; } set { ViewState["PageNum"] = value; } } #endregion #region = 3 CurrentPageIndex = /// <summary> /// 当前页数 /// </summary> public int CurrentPageIndex { get { int currentpageindex = 1; if (ViewState["CurrentPageIndex"] != null) { int.TryParse(ViewState["CurrentPageIndex"].ToString(), out currentpageindex); } else { if (this.Page.Request.QueryString["pages"] != null) { int.TryParse(this.Page.Request.QueryString["pages"].ToString(), out currentpageindex); } } currentpageindex = currentpageindex < 1 ? 1 : currentpageindex; currentpageindex = currentpageindex > PageCount ? PageCount : currentpageindex; return currentpageindex; } set { ViewState["CurrentPageIndex"] = value; } } #endregion #region = 4 PageCount = /// <summary> /// 总页数 /// </summary> public int PageCount { get { return (Count / PageNum) + ((Count % PageNum) == 0 ? 0 : 1); } } #endregion #region = 5 CssUrl = /// <summary> /// 分页样式 /// </summary> public string CssUrl { get { return ViewState["CssUrl"] != null ? ViewState["CssUrl"].ToString() : this.Page.ClientScript.GetWebResourceUrl(base.GetType(), "test.css.Pagination.css"); } //项目名称.文件夹.文件名 set { ViewState["CssUrl"] = value; } } #endregion #region = 6 Mode = /// <summary> /// Pagination的模式 /// </summary> public PaginationMode Mode { get { object obj = this.ViewState["Mode"]; return ((obj == null) ? PaginationMode.Get : ((PaginationMode)obj)); } set { this.ViewState["Mode"] = value; } } #endregion #region = 7 PagesName = /// <summary> /// 分页样式 /// </summary> public string PagesName { get { return ViewState["PagesName"] != null ? ViewState["PagesName"].ToString() : "pages"; } set { ViewState["PagesName"] = value; } } #endregion protected override HtmlTextWriterTag TagKey { get { return HtmlTextWriterTag.Div; } } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (this.PageCount > 1) { if ((this.Page != null) && (this.Page.Header != null)) { string cssKey = "PaginationCss"; if (this.Page.Header.FindControl(cssKey) == null) { HtmlLink child = new HtmlLink(); child.ID = cssKey; child.Href = CssUrl; child.Attributes["type"] = "text/css"; child.Attributes["rel"] = "stylesheet"; this.Page.Header.Controls.Add(child); } this.CssClass = "pagenumber"; } } } #region = RenderContents = protected override void RenderContents(HtmlTextWriter writer) { base.RenderContents(writer); if (this.PageCount > 1) { writer.Write("共"); writer.Write(Count); writer.Write("条"); writer.Write(" "); writer.Write("每页"); writer.Write(PageNum); writer.Write("条"); writer.Write(" "); writer.Write("共"); writer.Write(PageCount); writer.Write("页"); writer.Write(" "); writer.Write("当前为第"); writer.AddAttribute(HtmlTextWriterAttribute.Class, "f90"); writer.RenderBeginTag(HtmlTextWriterTag.B); writer.Write(CurrentPageIndex); writer.RenderEndTag(); writer.Write("页"); writer.Write(" "); writer.Write("选择页数:"); for (int i = 1; i < 5; i++) { if ((CurrentPageIndex - 5 + i) > 0) { if (this.Mode == PaginationMode.Get) { if (HttpContext.Current.Request.RawUrl.ToString().Contains(PagesName + "=")) { writer.AddAttribute(HtmlTextWriterAttribute.Href, Regex.Replace(HttpContext.Current.Request.RawUrl.ToString(), "(.+" + PagesName + "=)(\\d+)(.*)", "$1") + (CurrentPageIndex - 5 + i).ToString() + Regex.Replace(HttpContext.Current.Request.RawUrl.ToString(), "(.+" + PagesName + "=)(\\d+)(.*)", "$3")); } else if (HttpContext.Current.Request.QueryString.Count != 0) { writer.AddAttribute(HtmlTextWriterAttribute.Href, HttpContext.Current.Request.RawUrl.ToString() + "&" + PagesName + "=" + (CurrentPageIndex - 5 + i).ToString()); } else { writer.AddAttribute(HtmlTextWriterAttribute.Href, "?" + PagesName + "=" + (CurrentPageIndex - 5 + i).ToString()); } writer.AddAttribute(HtmlTextWriterAttribute.Class, "pagenumber"); writer.RenderBeginTag(HtmlTextWriterTag.A); writer.Write((CurrentPageIndex - 5 + i).ToString()); writer.RenderEndTag(); } else { PostBackOptions postBackOptions = this.GetPostBackOptions(CurrentPageIndex - 5 + i); string postBackEventReference = null; if (postBackOptions != null) { postBackEventReference = this.Page.ClientScript.GetPostBackEventReference(postBackOptions, true); } if (string.IsNullOrEmpty(postBackEventReference)) { postBackEventReference = "javascript:void(0)"; } writer.AddAttribute(HtmlTextWriterAttribute.Href, postBackEventReference); writer.AddAttribute(HtmlTextWriterAttribute.Class, "pagenumber"); writer.RenderBeginTag(HtmlTextWriterTag.A); writer.Write((CurrentPageIndex - 5 + i).ToString()); writer.RenderEndTag(); } } } writer.AddAttribute(HtmlTextWriterAttribute.Class, "current"); writer.RenderBeginTag(HtmlTextWriterTag.B); writer.Write(CurrentPageIndex); writer.RenderEndTag(); for (int i = 1; i < 5; i++) { if ((CurrentPageIndex + i) <= PageCount) { if (this.Mode == PaginationMode.Get) { if (HttpContext.Current.Request.RawUrl.ToString().Contains(PagesName + "=")) { writer.AddAttribute(HtmlTextWriterAttribute.Href, Regex.Replace(HttpContext.Current.Request.RawUrl.ToString(), "(.+" + PagesName + "=)(\\d+)(.*)", "$1") + (CurrentPageIndex + i).ToString() + Regex.Replace(HttpContext.Current.Request.RawUrl.ToString(), "(.+" + PagesName + "=)(\\d+)(.*)", "$3")); } else if (HttpContext.Current.Request.QueryString.Count != 0) { writer.AddAttribute(HtmlTextWriterAttribute.Href, HttpContext.Current.Request.RawUrl.ToString() + "&" + PagesName + "=" + (CurrentPageIndex + i).ToString()); } else { writer.AddAttribute(HtmlTextWriterAttribute.Href, "?" + PagesName + "=" + (CurrentPageIndex + i).ToString()); } writer.AddAttribute(HtmlTextWriterAttribute.Class, "pagenumber"); writer.RenderBeginTag(HtmlTextWriterTag.A); writer.Write((CurrentPageIndex + i).ToString()); writer.RenderEndTag(); } else { PostBackOptions postBackOptions = this.GetPostBackOptions(CurrentPageIndex + i); string postBackEventReference = null; if (postBackOptions != null) { postBackEventReference = this.Page.ClientScript.GetPostBackEventReference(postBackOptions, true); } if (string.IsNullOrEmpty(postBackEventReference)) { postBackEventReference = "javascript:void(0)"; } writer.AddAttribute(HtmlTextWriterAttribute.Href, postBackEventReference); writer.AddAttribute(HtmlTextWriterAttribute.Class, "pagenumber"); writer.RenderBeginTag(HtmlTextWriterTag.A); writer.Write((CurrentPageIndex + i).ToString()); writer.RenderEndTag(); } } } if ((CurrentPageIndex + 4) < PageCount) { writer.Write("..."); } if (this.Mode == PaginationMode.Get) { writer.Write(" "); writer.Write("跳转到第"); writer.Write("<input id=\"" + this.UniqueID + "\" type=\"text\" onkeypress=\"if(event.keyCode==13){location.href='"); if (HttpContext.Current.Request.RawUrl.ToString().Contains("pages=")) { writer.Write(Regex.Replace(HttpContext.Current.Request.RawUrl.ToString(), "(.+" + PagesName + "=)([\\w\\W^&]*)(.*)", "$1") + "'+this.value+'" + Regex.Replace(HttpContext.Current.Request.RawUrl.ToString(), "(.+" + PagesName + "=)([\\w\\W^&]*)(.*)", "$3") + "'"); } else if (HttpContext.Current.Request.QueryString.Count != 0) { writer.Write(HttpContext.Current.Request.RawUrl.ToString() + "&" + PagesName + "='+this.value"); } else { writer.Write(HttpContext.Current.Request.RawUrl.ToString() + "?" + PagesName + "='+this.value"); } writer.Write(";return false;}\" class=\"page_input\"/>"); writer.Write("页"); } } } #endregion private PostBackOptions GetPostBackOptions(int index) { PostBackOptions options = new PostBackOptions(this, index.ToString()); options.RequiresJavaScriptProtocol = true; return options; } public void RaisePostBackEvent(string eventArgument) { int num; if (int.TryParse(eventArgument, out num)) { this.CurrentPageIndex = num; } } } }
七、注:类文件的命名空间任意,嵌入资源路径要注意。
八、结构图如下:
九、vs工具箱--添加选项卡--选择荐--浏览(上面生成的dll文件)--确定完成。
或者:将dll文件拖曳入vs工具箱中即可。
十、拖曳使用控件。
十一、例句如下:
//头部自动生成引用 <%@ Register Assembly="test" Namespace="Common" TagPrefix="cc1" %> <!--控件拖入此页面自动生成如下内容--> <cc1:Pagination ID="Pagination1" runat="server" /> //后台代码样例 protected void Page_Load(object sender, EventArgs e) { Pagination1.Count = 1000; Pagination1.PageNum = 10; } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); //注:Repeater控件rptProblemCollection的数据源 //Pagination分页控件ID:UPProblemCollectionPagination //PageNum 页容量 //CurrentPageIndex当前页下标,注意sql拼写时判断CurrentPageIndex<=0时为1 if (isMyQuestion) rptProblemCollection.DataSource = MeetingQuestion.GetAdvanceQuestion(UPProblemCollectionPagination.CurrentPageIndex, UPProblemCollectionPagination.PageNum, MeetingID, CurrentUserID, AUserID, KeyString); else rptProblemCollection.DataSource = MeetingQuestion.GetAdvanceQuestion(UPProblemCollectionPagination.CurrentPageIndex, UPProblemCollectionPagination.PageNum, MeetingID, 0, AUserID, KeyString); rptProblemCollection.DataBind(); }
十二、效果图:
十三、附件:编译完成可用的 dll文件
发表评论
-
保存到桌面 功能
2013-11-19 15:34 924一、准备一个icon图标,图片类型必须是icon类型,不能通过 ... -
单点登录两种实现方案
2013-10-16 13:52 875说是两种其内在实质还是一个思路。 一种是使用js,另一种是使用 ... -
美化File控件-图片按键上传文件
2013-07-16 21:13 2454效果图: 一、显示样式 上传控件显示为一个图片 点击 ... -
dll项目添加服务引用
2011-07-24 16:17 1281当创建一个dll项目中添加了服务引用,但引用这个dll文件者又 ... -
邮件打开统计
2011-07-24 16:08 2805统计邮件是否被打开(或者打开次数) 1、在邮件的最下面(任意 ... -
匹配邮箱
2011-07-24 11:59 985匹配邮箱 (?m)^((([^\"\s]+)|(&q ... -
ListBox应用
2010-11-13 12:00 1005using System; using System.C ... -
rss 订阅
2010-11-11 20:50 1137//aspx页面内容 <%@ Page Langu ... -
枚举操作类
2010-10-27 20:25 870using System; using System.C ... -
自动执行服务程序 两法
2010-10-10 13:17 1110创建服务程序,利用此程序完成自动执行的工作。两种方法: 首先创 ... -
细边框Table制作 页面居中
2010-07-27 21:08 2577在页面布局时经常会使用到table,但如果使其bo ... -
通过泛型插入(更新)实体数据
2010-07-25 08:56 2404/// <summary> /// 通过泛型 ... -
DataReader 转换成实体(或List)
2010-07-25 08:39 8457/// <summary> /// Data ... -
自定义DateTable样例
2010-07-17 20:05 982记录流程备查 #region 创建自定义DataTabl ... -
发送邮件的两种方式
2010-07-11 14:44 1206一、实现代码如下: using System; using ... -
提示信息 换行 alert(); titile
2010-03-17 14:13 1828标签的titile属性内容文本换行可使用 代码 ... -
GridViw 绑定DataTable数据源 分页
2010-03-11 15:35 3061使用DataTable后分页有两种形式: 一、使用自定义的分页 ... -
SQL to Linq 翻译软件 Linqer
2010-03-06 10:28 2894先前我使用的是LINQPad,这个软件是一个编写Linq语句进 ... -
母板使用后样式问题
2010-03-03 20:07 928在单一aspx页面中操作没有什么问题,但要处理每个页面的登陆权 ... -
JQueryAPI1.4 中文版
2010-02-27 10:37 855API: 最新JQueryAPI1.4 中文版 大家分享--- ...
相关推荐
用户自定义控件,用户自定义控件,用户自定义控件,用户自定义控件,用户自定义控件,用户自定义控件,用户自定义控件,用户自定义控件,用户自定义控件用户自定义控件,用户自定义控件,用户自定义控件,用户自定义...
vb.net 自定义控件 自定义属性 UITypeEditor UI 类型编辑器 实例 提供一个示例 UITypeEditor,它使用 IWindowsFormsEditorService 显示用于用户输入的 Form。 IWindowsFormsEditorService 只能通过 PropertyGrid ...
当QTwidget的控件不满足开发者的需求的时候,如何在QT中快捷的添加自定义控件
C# 自定义控件的属性 添加自定义控件的事件
C#自定义控件库
c#自定义控件实例大全,.NET自定义控件实例大全,WINFORM自定义控件实例大全
C#自定义控件.rar
教程名称: 尚硅谷Android视频教程《自定义控件》Android自定义控件,是中高级程序员必须熟练掌握的技术之一。本套视频涵盖了安卓自定义开发过程中所有的技术问题,课程中讲授的例子全部来源于企业。学习本套视频后...
C#用户自定义控件C#用户自定义控件C#用户自定义控件C#用户自定义控件
自定义控件开发 自定义控件开发 自定义控件开发 自己知道这些了
LABVIEW自定义控件 你可以自己应用在你所需的领域
C# 自定义控件 自定义ComboBox。其他控件的自定义与此类似。
仅供初学者参考学习,Qt5开发的自定义控件 许多精美样式控件 觉得不错的小伙给予我反馈 还有四五十套源码之后慢慢上传分享
C#的ListView添加各种自定义控件,CheckBox,ComboBox等
labveiw自定义控件、以及一些各种控件大约有几百个、下载之后需要进行安装、任何labview版本都可以安装
c# winform自定义控件包括button、进度条、box、提示框、外观等 内含使用实例工程方便使用和上手
C#写的 自定义控件.ppt以及源代码 自定义控件.ppt以及源代码 自定义控件.ppt以及源代码
C# 自定义控件实例 C# 自定义控件实例 C# 自定义控件实例 button,Control,ProgressBar,tabControl, TrackBar
自定义控件(冒泡事件)源码(WebControl) 自定义控件(冒泡事件)源码(WebControl) 自定义控件(冒泡事件)源码(WebControl) 自定义控件(冒泡事件)源码(WebControl)