My Opera is closing 3rd of March

knowledge, skill, experience ... about IT, computer, programming ...

Kiến thức tạo nên sức mạnh, năng lực đạp đổ bằng cấp...!

Paging with Repeater control in ASP.NET [C#]

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.

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>
<asp:repeater ID="Repeater1" runat="server"> <itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "Product") %>
</itemtemplate> </asp:repeater>

Working with DropDownList and ListBox Controls in ASP.NETLinux nào hỗ trợ mạng tốt nhất????

Comments

Unregistered user Sunday, April 8, 2007 9:59:54 AM

Anonymous writes: Suu tam them: Cách 1: Sử dụng phương thức Fill ( dataSet As DataSet, startRecord As Integer, maxRecords As Integer, srcTable As String ) As Integer của DataAdapter để lấy một số hữu hạn maxRecords bản ghi (từ startRecord)đưa vào DataSet rồi sau đó dùng DataSet làm nguồn dữ liệu cho Repeater. Cách 2: Phân trang dữ liệu ngay trong StoredProcedure để lấy dữ liệu ra.

Unregistered user Wednesday, April 1, 2009 12:57:31 PM

Anonymous writes: rat hay, cam on nhe

Unregistered user Sunday, April 26, 2009 3:50:21 PM

Anonymous writes: ddd

Unregistered user Monday, November 30, 2009 8:10:22 AM

khuccui2002 writes: Thanks

Unregistered user Saturday, February 6, 2010 4:06:22 AM

littlegirl writes: Cũng tạm tạm :d

Write a comment

New comments have been disabled for this post.

February 2014
S M T W T F S
January 2014March 2014
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28