Click here to Skip to main content
15,885,546 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 278.5K   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

 
GeneralRe: problem Pin
Pathik H Rawal27-Mar-05 17:45
Pathik H Rawal27-Mar-05 17:45 
GeneralRe: problem Pin
Anonymous28-Mar-05 18:26
Anonymous28-Mar-05 18:26 
GeneralRe: problem Pin
Anonymous28-Mar-05 18:38
Anonymous28-Mar-05 18:38 
GeneralRe: problem Pin
Anonymous29-Mar-05 13:38
Anonymous29-Mar-05 13:38 
GeneralRe: problem Pin
zubairuddin19-Jun-05 19:49
zubairuddin19-Jun-05 19:49 
QuestionCan we use any templates when we display data? Pin
gun4boy20-Feb-05 21:36
gun4boy20-Feb-05 21:36 
AnswerRe: Can we use any templates when we display data? Pin
Pathik H Rawal23-Feb-05 16:45
Pathik H Rawal23-Feb-05 16:45 
GeneralRe: Can we use any templates when we display data? Pin
nguyenlinhhaivt17-Sep-06 21:28
nguyenlinhhaivt17-Sep-06 21:28 
I meet a broblem with avarible "pageds".
I don't see it has defined.
When i define it:" Dim pageds as new PageDataSource"
It has Error:"Type PageDataSource is not defined".
Can you help me about this Error.
Thanks!

nguyenlinhhaivt@yahoo.com

nguyenlinhhaivt@yahoo.com
GeneralRe: Can we use any templates when we display data? Pin
nguyenlinhhaivt17-Sep-06 21:41
nguyenlinhhaivt17-Sep-06 21:41 

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.