ASP.NET Repeater 分页显示
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ASP.NET Repeater 分页显示相关的知识,希望对你有一定的参考价值。
通过创建多一个Repeater 来作为分页用
<div style="overflow: hidden; padding-bottom: 20px; text-align: center;"> <asp:Repeater ID="rptPaging" runat="server" OnItemCommand="rptPaging_ItemCommand"> <ItemTemplate> <asp:LinkButton ID="btnPage" style="background:darkgray; border:solid 1px #666; font:8pt tahoma;" CommandName="Page" CommandArgument="<%# Container.DataItem %>" runat="server" ForeColor="White" Font-Bold="True"><%#Container.DataItem %> </asp:LinkButton> </ItemTemplate> </asp:Repeater> </div>
后台代码
//此属性将包含当前页码 public int PageNumber { get { if (ViewState["PageNumber"] != null) { return Convert.ToInt32(ViewState["PageNumber"]); } else { return 0; } } set { ViewState["PageNumber"] = value; } }
//绑定记录 public void BindList() { DataTable dt = new DataTable(); if (am.ReadMyBrowse(uiv.UserID, out dt) > 0) { if (dt != null && dt.Rows.Count > 0) { PagedDataSource pgitems = new PagedDataSource(); pgitems.DataSource = dt.DefaultView; pgitems.AllowPaging = true; pgitems.PageSize = 20; pgitems.CurrentPageIndex = PageNumber; if (pgitems.PageCount > 1) { rptPaging.Visible = true; ArrayList pages = new ArrayList(); for (int i = 0; i <= pgitems.PageCount - 1; i++) { pages.Add((i + 1).ToString()); } rptPaging.DataSource = pages; rptPaging.DataBind(); } else { rptPaging.Visible = false; } repeater1.DataSource = pgitems; repeater1.DataBind(); //repeater1.DataSource = dt; //repeater1.DataBind(); } else { repeater1.DataSource = ""; repeater1.DataBind(); rptPaging.DataSource = ""; rptPaging.DataBind(); } } else { repeater1.DataSource = ""; repeater1.DataBind(); rptPaging.DataSource = ""; rptPaging.DataBind(); } }
protected void rptPaging_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e) { PageNumber = Convert.ToInt32(e.CommandArgument) - 1; BindRepeater(); }
效果:
以上是关于ASP.NET Repeater 分页显示的主要内容,如果未能解决你的问题,请参考以下文章
ASP.NET WebForms:Repeater 控件中的图像尺寸模式