Click here to Skip to main content
Licence 
First Posted 8 Oct 2004
Views 188,313
Bookmarked 47 times

Paging with Repeater control in ASP.NET

By | 8 Oct 2004 | Article
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

About the Author

pathikhrawal



India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmemberhostrajeev1:54 21 Sep '11  
GeneralExcellant! Pinmemberkavitharavi18:45 8 Jun '11  
GeneralMy vote of 1 Pinmemberprakash.kumar.jmd2:29 26 Aug '10  
GeneralMy vote of 1 Pinmembermehran ghainian hasaruye1:08 27 Jul '10  
GeneralMy vote of 1 PinmemberQuiero7:48 19 Mar '10  
GeneralC# version of this and IsLastPage problem Pinmemberrammi.cz23:37 24 Nov '09  
GeneralRe: C# version of this and IsLastPage problem Pinmemberrammi.cz23:51 24 Nov '09  
Generalthx alot..excellent code PinmemberShilpi Singh22:45 12 May '09  
Generalthanks thanks many thanks Pinmember Xmen 18:44 1 Feb '09  
GeneralNice article PinmemberIvan (Zaragoza)9:06 14 Dec '08  
Generalits excellent--- working fine PinmemberMember 283505622:52 7 Nov '08  
GeneralWorking with querystrings PinmemberDejan]10:01 20 Dec '07  
GeneralGood Info...Needs Work PinmemberAKwebmaster11:54 30 Oct '07  
GeneralPaging with Repeater control in ASP.NET PinmemberGanesan S23:51 9 Aug '07  
QuestionPaging with Repeater control in ASP.NET PinmemberGanesan S3:08 28 Jun '07  
Generalaccess connection Pinmemberimperialx17:12 14 Apr '07  
Generaldeclare ds Pinmemberimperialx16:35 14 Apr '07  
GeneralRe: declare ds Pinmemberimperialx16:59 14 Apr '07  
Generalthanks thanks thanks PinmemberMember #38131211:15 28 Mar '07  
GeneralThanx Man..! PinmemberRizshaikh22:17 25 Feb '07  
Generalshould declare PageDataSource variable first Pinmemberlym6210:00 2 Aug '06  
dim pageds as new PageDataSource
 
after that jz use ur skill to use this pageds.
 
Good code actually.Help me solve datalist paging problem.Big Grin | :-D
QuestionWhat t1 in this code please explain Pinmemberasifmehdi21:13 9 Jun '06  
GeneralExcellent piece of work! PinmemberBharti4:46 24 Apr '06  
Generalpageds Pinmembertaher ben taib22:40 14 Jun '05  
GeneralRe: pageds Pinmemberjresins16:16 20 Jul '05  

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.

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