Click here to Skip to main content
Click here to Skip to main content

Paging with Repeater control in ASP.NET

, 8 Oct 2004
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

Comments and Discussions

 
GeneralMy vote of 2 Pinmembermbsmbs6-Sep-12 5:53 
BugDatabase call for each request PinmemberParimal@Cybage26-Jun-12 4:59 
GeneralMy vote of 5 Pinmemberhostrajeev21-Sep-11 2:54 
GeneralExcellant! Pinmemberkavitharavi8-Jun-11 19:45 
GeneralMy vote of 1 Pinmemberprakash.kumar.jmd26-Aug-10 3:29 
GeneralMy vote of 1 Pinmembermehran ghainian hasaruye27-Jul-10 2:08 
GeneralMy vote of 1 PinmemberQuiero19-Mar-10 8:48 
GeneralC# version of this and IsLastPage problem Pinmemberrammi.cz25-Nov-09 0:37 
GeneralRe: C# version of this and IsLastPage problem Pinmemberrammi.cz25-Nov-09 0:51 
Generalthx alot..excellent code PinmemberShilpi Singh12-May-09 23:45 
Generalthanks thanks many thanks Pinmember Xmen 1-Feb-09 19:44 
GeneralNice article PinmemberIvan (Zaragoza)14-Dec-08 10:06 
Generalits excellent--- working fine PinmemberMember 28350567-Nov-08 23:52 
GeneralWorking with querystrings PinmemberDejan]20-Dec-07 11:01 
GeneralGood Info...Needs Work PinmemberAKwebmaster30-Oct-07 12:54 
GeneralPaging with Repeater control in ASP.NET PinmemberGanesan S10-Aug-07 0:51 
QuestionPaging with Repeater control in ASP.NET PinmemberGanesan S28-Jun-07 4:08 
Generalaccess connection Pinmemberimperialx14-Apr-07 18:12 
Generaldeclare ds Pinmemberimperialx14-Apr-07 17:35 
GeneralRe: declare ds Pinmemberimperialx14-Apr-07 17:59 
Generalthanks thanks thanks PinmemberMember #381312128-Mar-07 2:15 
GeneralThanx Man..! PinmemberRizshaikh25-Feb-07 23:17 
Generalshould declare PageDataSource variable first Pinmemberlym6212-Aug-06 1:00 
QuestionWhat t1 in this code please explain Pinmemberasifmehdi9-Jun-06 22:13 
GeneralExcellent piece of work! PinmemberBharti24-Apr-06 5:46 
Generalpageds Pinmembertaher ben taib14-Jun-05 23:40 
GeneralRe: pageds Pinmemberjresins20-Jul-05 17:16 
GeneralRe: pageds PinmemberIvan (Zaragoza)14-Dec-08 10:08 
Generalproblem Pinmemberayeletatary8-Mar-05 6:58 
GeneralRe: problem Pinmemberaayu17-Mar-05 23:39 
GeneralRe: problem PinsussAnonymous25-Mar-05 7:00 
GeneralRe: problem Pinmemberaayu27-Mar-05 18:45 
GeneralRe: problem PinsussAnonymous28-Mar-05 19:26 
GeneralRe: problem PinsussAnonymous28-Mar-05 19:38 
GeneralRe: problem PinsussAnonymous29-Mar-05 14:38 
GeneralRe: problem Pinmemberzubairuddin19-Jun-05 20:49 
QuestionCan we use any templates when we display data? Pinmembergun4boy20-Feb-05 22:36 
AnswerRe: Can we use any templates when we display data? Pinmemberaayu23-Feb-05 17:45 
GeneralRe: Can we use any templates when we display data? Pinmembernguyenlinhhaivt17-Sep-06 22:28 
GeneralRe: Can we use any templates when we display data? Pinmembernguyenlinhhaivt17-Sep-06 22: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
Web03 | 2.8.1411023.1 | Last Updated 9 Oct 2004
Article Copyright 2004 by pathikhrawal
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid