• AspNetPage分页(repeater),自己做的例子基本代码


    前台:

    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile
    ="News_list.aspx.cs" Inherits="News_list" Title="公告列表" %>

    <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:Repeater runat="server" ID="rptNewsList">
    <HeaderTemplate><ol></HeaderTemplate>
    <ItemTemplate>
    <li><a href='NewsContent.aspx?Nid=<%#Eval("NewsId") %>' title='<%#Eval("NewsTitle") %>'>
    <%#Cutstring.StringTruncat(Eval("NewsTitle").ToString(),10,"...")%>
    </a><span>
    <%#Eval("PubTime", "{0:yyyy-MM-dd}")%>
    </span></li>
    </ItemTemplate>
    <FooterTemplate></ol></FooterTemplate>
    </asp:Repeater>
    <webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged" NextPageText="下一页" PageSize="5" PrevPageText="上一页">
    </webdiyer:AspNetPager>
    </asp:Content>

    后台:

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    Bind();
    }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
    //DataTable Dt = new NewsManager().wz_News_Select_All();
    //AspNetPager1.RecordCount = Dt.Rows.Count;//获取数据的总数
    //PagedDataSource pds = new PagedDataSource();
    //pds.AllowPaging = true;
    //pds.DataSource = Dt.DefaultView;//为控件绑定数据
    //pds.PageSize = AspNetPager1.PageSize;//获取每页显示的数量
    //pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
    //rptNewsList.DataSource = pds;
    //rptNewsList.DataBind();
    Bind();
    }
    private void Bind()
    {
    DataTable Dt
    = new NewsManager().wz_News_Select_All();
    AspNetPager1.RecordCount
    = Dt.Rows.Count;//获取数据的总数
    PagedDataSource pds = new PagedDataSource();
    pds.AllowPaging
    = true;
    pds.DataSource
    = Dt.DefaultView;//为控件绑定数据
    pds.PageSize = AspNetPager1.PageSize;//获取每页显示的数量
    pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
    rptNewsList.DataSource
    = pds;
    rptNewsList.DataBind();
    }
  • 相关阅读:
    线性表链式存储方式的C语言实现
    线性表顺序存储方式的C语言实现
    抽象数据类型Triplet的C语言实现
    Python之装饰器
    Django-auth(认证系统)
    Django-中间件
    Django-form表单
    Python cookie、session和自定义分页
    Django 使用ajax上传文件
    Python之迭代器和生成器
  • 原文地址:https://www.cnblogs.com/ret00100/p/1686096.html
Copyright © 2020-2023  润新知