.NET实现Repeater控件+AspNetPager控件分页
来源:
中文源码网 浏览:138 次 日期:2024-05-12 21:37:26
【下载文档: .NET实现Repeater控件+AspNetPager控件分页.txt 】
.NET实现Repeater控件+AspNetPager控件分页
当然首先你要把bin文件放进你的项目,并加到你的工具栏去
//页头需引用的
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
控件部分(格式已经设计好)
LastPageText="
:" NextPageText="
8"
PrevPageText="
7" ShowCustomInfoSection="Left" InputBoxStyle="width:19px"
TextAfterInputBox="页" TextBeforeInputBox="转到第" CustomInfoHTML="共检索到
%RecordCount%条记录 页次:
%CurrentPageIndex%/%PageCount% 每页
%PageSize%条"
HorizontalAlign="Right" Width="100%" ShowInputBox="Always" OnPageChanged="AspNetPager1_PageChanged"
PageSize="20" ShowBoxThreshold="1">
后台绑定的代码
void databind()
{
int QYId = Convert.ToInt32(Request.Cookies["CompenyUser"].Value);//企业的Id
DataTable dt = bll.Viewlist(QYId);
this.AspNetPager1.RecordCount = dt.Rows.Count;//获取数据的总数
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;//为控件绑定数据
pds.AllowPaging = true;//分页启用
pds.PageSize = AspNetPager1.PageSize;//获取每页显示的数量
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
Repeater1.DataSource = pds;
Repeater1.DataBind();
}
分页,只需要把绑定放在AspNetPager1_PageChanged 事件里
再给大家一个实例
前台页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TF_Product.aspx.cs" Inherits="TF_Product" %>
<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>
通服产品后台代码
Tb_productsHelper helper = new Tb_productsHelper();
IList
list = helper.GetAllListBySql(product_sql);
this.AspNetPager1.RecordCount = list.Count;//绑定总数量
this.AspNetPager1.AlwaysShow = true;
//先声明一个分页类对象
PagedDataSource ps = new PagedDataSource();
ps.AllowPaging = true;
ps.PageSize = this.AspNetPager1.PageSize;
ps.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex-1;
ps.DataSource = list;
this.rp.DataSource = ps;
this.rp.DataBind();