改造办法是自己写一个控件,让它继承GridView或Repeater,并实现IPageableItemContainer 接口。下面要发的是国外某高手写的代码,测试有效。具体使用的时候,要建一个类库项目,把代码编译成dll后,就可以添加到VS的工具箱里了!
一、自定义Repeater
代码如下 | 复制代码 |
using System.Web.UI; namespace WYJ.Web.Controls /// /// /// /// //if (Page.IsPostBack) // if (!IsBoundUsingDataSourceID && PersistentDataSource && ViewState["DataSource"] != null) protected override void OnLoad(System.EventArgs e) if (!IsBoundUsingDataSourceID && PersistentDataSource && ViewState["DataSource"] != null) } base.OnLoad(e); }
if (TotalRows > -1) /// /// if (dataObjects == null && this.DataSource != null) if (!PagingInDataSource && MaximumRows != -1 && dataObjects != null) if (dataObjects != null) } ViewState["TotalRows"] = i; if (!IsBoundUsingDataSourceID && PersistentDataSource) SetPageProperties(StartRowIndex, MaximumRows, true); if (PagingInDataSource && !Page.IsPostBack) return dataObjects;
/// /// } }
|
ASPX页面要做的事情(以我网站的留言板为例):
首先得把标签注册进来
代码如下 | 复制代码 |
<%@ Register Assembly="WYJ.Web.Controls" Namespace="WYJ.Web.Controls" TagPrefix="WYJ" %> |
然后添加我们的Repeater
之后添加.NET自带的DataPager,并自定义一些分页样式
代码如下 | 复制代码 |
共<%=Math.Ceiling((double)DataPager1.TotalRowCount / DataPager1.PageSize)%>页,<%=DataPager1.TotalRowCount%>条记录,每页显示 <asp:LinkButton ID="lnkbtn10" CssClass="currentpagesize" runat="server" OnClick="lnkbtn10_Click">10
|
后台代码:
分页部分不需要代码。下面发的代码是切换每页显示数量的:
代码如下 | 复制代码 |
protected void lnkbtn10_Click(object sender, EventArgs e) protected void lnkbtn20_Click(object sender, EventArgs e) protected void lnkbtn30_Click(object sender, EventArgs e)
|
二、自定义GridView
代码如下 | 复制代码 |
using System; namespace WYJ.Web.Controls /// /// // if the paging feature is enabled, determine the total number of rows in the datasource // raise the row count available event // make sure the top and bottom pager rows are not visible if (this.BottomPagerRow != null) /// if (this.PageIndex != newPageIndex) isCanceled = args.Cancel; // if the event wasn't cancelled change the paging values if (databind) /// /// /// /// |
用法与Repeater类似,不多发了~
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级