Paging with Repeater control in ASP.NET [C#]
Wednesday, April 4, 2007 11:01:05 AM
Repeater and DataList controls offer a quick and flexible means of displaying data on a ASPX page. But they offer no paging functionality built in. The DataGrid control has in-built paging but it's structure is more rigid. There are several articles on various ASP.NET Resource Sites that offer solutions, but I'm going to show you how to use the PagedDataSource class. The PagedDataSource class encapsulates the properties of the DataGrid control that allow it to perform paging. But we can use the class with Repeater and DataList controls to perform paging in much the same way as a DataGrid. First, we need to add some code to the ASPX page, you can download a demo by clicking the link at bottom. <script language="C#" runat="server"> public void Page_Load(Object src,EventArgs e) { DataSet ds; //Instanciate Dataset PagedDataSource objPds = new PagedDataSource(); objPds.DataSource = ds.Tables[0].DefaultView; objPds.AllowPaging = true; objPds.PageSize = 5; int CurPage; if (Request.QueryString["Page"] != null) CurPage=Convert.ToInt32(Request.QueryString["Page"]); else CurPage=1; objPds.CurrentPageIndex = CurPage-1; lblCurrentPage.Text = "Page: " + CurPage.ToString(); if (!objPds.IsFirstPage) lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage-1); if (!objPds.IsLastPage) lnkNext.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage+1); Repeater1.DataSource=objPds; Repeater1.DataBind(); } < /script> And in the body of the page:
| <asp:label ID="lblCurrentPage" runat="server"> </asp:label> |
| <asp:HyperLink id="lnkPrev" runat="server"><< Prev</asp:HyperLink> <asp:HyperLink id="lnkNext" runat="server">Next >></asp:HyperLink> |
| <%# DataBinder.Eval(Container.DataItem, "Product") %> |







Unregistered user # Sunday, April 8, 2007 9:59:54 AM
Unregistered user # Wednesday, April 1, 2009 12:57:31 PM
Unregistered user # Sunday, April 26, 2009 3:50:21 PM
Unregistered user # Monday, November 30, 2009 8:10:22 AM
Unregistered user # Saturday, February 6, 2010 4:06:22 AM