Click here to Skip to main content
15,937,127 members
Articles / Web Development / ASP.NET
Article

Paging with Repeater control in ASP.NET

Rate me:
Please Sign up or sign in to vote.
2.80/5 (43 votes)
8 Oct 2004 280.2K   48   40
Paging with Repeater control in ASP.NET.

Introduction

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 its 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.

VB
Private Sub Page_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    Dim myConnection As New _
      SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
    Dim myDA As New SqlClient.SqlDataAdapter("Select * from dtsDefect", _
                                                             myConnection)
    myDA.Fill(ds, "t1")
    pageds.DataSource = ds.Tables("t1").DefaultView
    pageds.AllowPaging = True
    pageds.PageSize = 4
    Dim curpage As Integer

    If Not IsNothing(Request.QueryString("Page")) Then
        curpage = Convert.ToInt32(Request.QueryString("Page"))
    Else
        curpage = 1
    End If

    pageds.CurrentPageIndex = curpage - 1
    lblCurrpage.Text = "Page: " + curpage.ToString()

    If Not pageds.IsFirstPage Then
        lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + _
                                       "?Page=" + CStr(curpage - 1)
    End If

    If Not pageds.IsLastPage Then
        lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + _
                                       "?Page=" + CStr(curpage + 1)
    End If

    Repeater1.DataSource = pageds
    Repeater1.DataBind()
End Sub

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 2 Pin
MB Seifollahi6-Sep-12 4:53
professionalMB Seifollahi6-Sep-12 4:53 
BugDatabase call for each request Pin
Parimal@Cybage26-Jun-12 3:59
Parimal@Cybage26-Jun-12 3:59 
GeneralMy vote of 5 Pin
hostrajeev21-Sep-11 1:54
hostrajeev21-Sep-11 1:54 
GeneralExcellant! Pin
kavitharavi8-Jun-11 18:45
kavitharavi8-Jun-11 18:45 
GeneralMy vote of 1 Pin
prakash.kumar.jmd26-Aug-10 2:29
prakash.kumar.jmd26-Aug-10 2:29 
GeneralMy vote of 1 Pin
mehran ghainian hasaruye27-Jul-10 1:08
mehran ghainian hasaruye27-Jul-10 1:08 
GeneralMy vote of 1 Pin
Quiero19-Mar-10 7:48
Quiero19-Mar-10 7:48 
GeneralC# version of this and IsLastPage problem Pin
rammi.cz24-Nov-09 23:37
rammi.cz24-Nov-09 23:37 
GeneralRe: C# version of this and IsLastPage problem Pin
rammi.cz24-Nov-09 23:51
rammi.cz24-Nov-09 23:51 
Generalthx alot..excellent code Pin
Shilpi Singh12-May-09 22:45
Shilpi Singh12-May-09 22:45 
Generalthanks thanks many thanks Pin
Xmen Real 1-Feb-09 18:44
professional Xmen Real 1-Feb-09 18:44 
GeneralNice article Pin
Ivan (Zaragoza)14-Dec-08 9:06
Ivan (Zaragoza)14-Dec-08 9:06 
Generalits excellent--- working fine Pin
Member 28350567-Nov-08 22:52
Member 28350567-Nov-08 22:52 
GeneralWorking with querystrings Pin
Dejan]20-Dec-07 10:01
Dejan]20-Dec-07 10:01 
GeneralGood Info...Needs Work Pin
AKwebmaster30-Oct-07 11:54
AKwebmaster30-Oct-07 11:54 
GeneralPaging with Repeater control in ASP.NET Pin
Ganesan Sankaran9-Aug-07 23:51
Ganesan Sankaran9-Aug-07 23:51 
QuestionPaging with Repeater control in ASP.NET Pin
Ganesan Sankaran28-Jun-07 3:08
Ganesan Sankaran28-Jun-07 3:08 
Generalaccess connection Pin
imperialx14-Apr-07 17:12
imperialx14-Apr-07 17:12 
Generaldeclare ds Pin
imperialx14-Apr-07 16:35
imperialx14-Apr-07 16:35 
GeneralRe: declare ds Pin
imperialx14-Apr-07 16:59
imperialx14-Apr-07 16:59 
Generalthanks thanks thanks Pin
sahelk28-Mar-07 1:15
sahelk28-Mar-07 1:15 
GeneralThanx Man..! Pin
Rizshaikh25-Feb-07 22:17
Rizshaikh25-Feb-07 22:17 
Generalshould declare PageDataSource variable first Pin
lym6212-Aug-06 0:00
lym6212-Aug-06 0:00 
QuestionWhat t1 in this code please explain Pin
asifmehdi9-Jun-06 21:13
asifmehdi9-Jun-06 21:13 
GeneralExcellent piece of work! Pin
WiseLearner24-Apr-06 4:46
WiseLearner24-Apr-06 4:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.