Click here to Skip to main content
11,634,827 members (65,140 online)
Click here to Skip to main content

Paging with Repeater control in ASP.NET

, 8 Oct 2004 232.5K 48
Rate this:
Please Sign up or sign in to vote.
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.

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

Share

About the Author

pathikhrawal
India India
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 2 Pin
mbsmbs6-Sep-12 4:53
membermbsmbs6-Sep-12 4:53 
BugDatabase call for each request Pin
Parimal@Cybage26-Jun-12 3:59
memberParimal@Cybage26-Jun-12 3:59 
GeneralMy vote of 5 Pin
hostrajeev21-Sep-11 1:54
memberhostrajeev21-Sep-11 1:54 
GeneralExcellant! Pin
kavitharavi8-Jun-11 18:45
memberkavitharavi8-Jun-11 18:45 
GeneralMy vote of 1 Pin
prakash.kumar.jmd26-Aug-10 2:29
memberprakash.kumar.jmd26-Aug-10 2:29 
GeneralMy vote of 1 Pin
mehran ghainian hasaruye27-Jul-10 1:08
membermehran ghainian hasaruye27-Jul-10 1:08 
GeneralMy vote of 1 Pin
Quiero19-Mar-10 7:48
memberQuiero19-Mar-10 7:48 
GeneralC# version of this and IsLastPage problem Pin
rammi.cz24-Nov-09 23:37
memberrammi.cz24-Nov-09 23:37 
GeneralRe: C# version of this and IsLastPage problem Pin
rammi.cz24-Nov-09 23:51
memberrammi.cz24-Nov-09 23:51 
Generalthx alot..excellent code Pin
Shilpi Singh12-May-09 22:45
memberShilpi Singh12-May-09 22:45 
Generalthanks thanks many thanks Pin
Xmen 1-Feb-09 18:44
member Xmen 1-Feb-09 18:44 
GeneralNice article Pin
Ivan (Zaragoza)14-Dec-08 9:06
memberIvan (Zaragoza)14-Dec-08 9:06 
Generalits excellent--- working fine Pin
Member 28350567-Nov-08 22:52
memberMember 28350567-Nov-08 22:52 
GeneralWorking with querystrings Pin
Dejan]20-Dec-07 10:01
memberDejan]20-Dec-07 10:01 
GeneralGood Info...Needs Work Pin
AKwebmaster30-Oct-07 11:54
memberAKwebmaster30-Oct-07 11:54 
GeneralPaging with Repeater control in ASP.NET Pin
Ganesan S9-Aug-07 23:51
memberGanesan S9-Aug-07 23:51 
QuestionPaging with Repeater control in ASP.NET Pin
Ganesan S28-Jun-07 3:08
memberGanesan S28-Jun-07 3:08 
Generalaccess connection Pin
imperialx14-Apr-07 17:12
memberimperialx14-Apr-07 17:12 
Generaldeclare ds Pin
imperialx14-Apr-07 16:35
memberimperialx14-Apr-07 16:35 
GeneralRe: declare ds Pin
imperialx14-Apr-07 16:59
memberimperialx14-Apr-07 16:59 
Generalthanks thanks thanks Pin
Member #381312128-Mar-07 1:15
memberMember #381312128-Mar-07 1:15 
GeneralThanx Man..! Pin
Rizshaikh25-Feb-07 22:17
memberRizshaikh25-Feb-07 22:17 
Generalshould declare PageDataSource variable first Pin
lym6212-Aug-06 0:00
memberlym6212-Aug-06 0:00 
QuestionWhat t1 in this code please explain Pin
asifmehdi9-Jun-06 21:13
memberasifmehdi9-Jun-06 21:13 
GeneralExcellent piece of work! Pin
Bharti24-Apr-06 4:46
memberBharti24-Apr-06 4:46 
Generalpageds Pin
taher ben taib14-Jun-05 22:40
membertaher ben taib14-Jun-05 22:40 
GeneralRe: pageds Pin
jresins20-Jul-05 16:16
memberjresins20-Jul-05 16:16 
GeneralRe: pageds Pin
Ivan (Zaragoza)14-Dec-08 9:08
memberIvan (Zaragoza)14-Dec-08 9:08 
Generalproblem Pin
ayeletatary8-Mar-05 5:58
memberayeletatary8-Mar-05 5:58 
GeneralRe: problem Pin
aayu17-Mar-05 22:39
memberaayu17-Mar-05 22:39 
GeneralRe: problem Pin
Anonymous25-Mar-05 6:00
sussAnonymous25-Mar-05 6:00 
GeneralRe: problem Pin
aayu27-Mar-05 17:45
memberaayu27-Mar-05 17:45 
GeneralRe: problem Pin
Anonymous28-Mar-05 18:26
sussAnonymous28-Mar-05 18:26 
GeneralRe: problem Pin
Anonymous28-Mar-05 18:38
sussAnonymous28-Mar-05 18:38 
GeneralRe: problem Pin
Anonymous29-Mar-05 13:38
sussAnonymous29-Mar-05 13:38 
GeneralRe: problem Pin
zubairuddin19-Jun-05 19:49
memberzubairuddin19-Jun-05 19:49 
QuestionCan we use any templates when we display data? Pin
gun4boy20-Feb-05 21:36
membergun4boy20-Feb-05 21:36 
AnswerRe: Can we use any templates when we display data? Pin
aayu23-Feb-05 16:45
memberaayu23-Feb-05 16:45 
GeneralRe: Can we use any templates when we display data? Pin
nguyenlinhhaivt17-Sep-06 21:28
membernguyenlinhhaivt17-Sep-06 21:28 
GeneralRe: Can we use any templates when we display data? Pin
nguyenlinhhaivt17-Sep-06 21:41
membernguyenlinhhaivt17-Sep-06 21:41 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150728.1 | Last Updated 9 Oct 2004
Article Copyright 2004 by pathikhrawal
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid