网络编程 
首页 > 网络编程 > 浏览文章

.NET实现Repeater控件+AspNetPager控件分页

(编辑:jimmy 日期: 2024/5/20 浏览:3 次 )

当然首先你要把bin文件放进你的项目,并加到你的工具栏去

//页头需引用的
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

控件部分(格式已经设计好)
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" FirstPageText="<font face='Webdings'>9</font>"
 LastPageText="<font face='Webdings'>:</font>" NextPageText="<font face='Webdings'>8</font>"
 PrevPageText="<font face='Webdings'>7</font>" ShowCustomInfoSection="Left" InputBoxStyle="width:19px"
 TextAfterInputBox="页" TextBeforeInputBox="转到第" CustomInfoHTML="共检索到<strong>%RecordCount%</strong>条记录 页次:<strong>%CurrentPageIndex%/%PageCount%</strong> 每页<strong>%PageSize%</strong>条"
 HorizontalAlign="Right" Width="100%" ShowInputBox="Always" OnPageChanged="AspNetPager1_PageChanged"
 PageSize="20" ShowBoxThreshold="1">
</webdiyer:AspNetPager>

后台绑定的代码

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" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
 
<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>通服产品</title>
  <script src="/UploadFiles/2021-04-02/jquery.js">

后台代码

Tb_productsHelper helper = new Tb_productsHelper();
    IList<Tb_productsInfo> 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();

上一篇:灵活使用asp.net中的gridview控件
下一篇:asp.net数据验证控件
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网