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();
}