改造办法是自己写一个控件,让它继承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页面要做的事情(以我网站的留言板为例):
首先得把标签注册进来
| 代码如下 | 复制代码 |
然后添加我们的Repeater
| 代码如下 | 复制代码 |
|
|
|
之后添加.NET自带的DataPager,并自定义一些分页样式
| 代码如下 | 复制代码 |
|
共页,条记录,每页显示 asp:LinkButton ID="lnkbtn10" CssClass="currentpagesize" runat="server" OnClick="lnkbtn10_Click">10 20 30 ShowPreviousPageButton="False" FirstPageText="首页" /> ShowPreviousPageButton="False" LastPageText="尾页" />
|
|
后台代码:
分页部分不需要代码。下面发的代码是切换每页显示数量的:
| 代码如下 | 复制代码 |
|
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类似,不多发了~
DeepSeek多模态怎么样及保姆级配置教程(codex、claude)实用指南
WSL2+Docker+Ollama本地部署大模型思路和实践指南(Qwen1.8b)实用指南
DeepSeek Harness热门插件盘点:10个实用插件,覆盖多Agent、上下文和多模态实用指南
grep文本搜索与正则表达式完整代码示例实用指南
AI漫剧伪装直男1‑24集无雾版夸克网盘资源免费分享
AI漫剧玉僧入尘1-68集无雾无删版夸克网盘资源免费分享