Results 1 to 2 of 2

Thread: [RESOLVED] Paging with a datarepeater

  1. #1

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316

    Resolved [RESOLVED] Paging with a datarepeater

    Adding a paging feature to data displayed in a data repeater is decidedly easy with the simple addition of a paged data source.

    I couldn't find much information on this topic in this forum but I did find some decent C# code elsewhere that I translated to VB.Net. Since this forum has helped me more times than I can count I always like to post my solutions in case they some day help someone else.

    Use this code in your page load and make sure you have a label called lblCurrentPage above your repeater and two hyperlinks called lnkPrev and lnkNext below your reader. You will also need a data adapter (mine is called sdaData here).

    This code handles the rest.

    VB Code:
    1. If Not Me.Page.IsPostBack Then
    2.             Dim cn As New SqlClient.SqlConnection(Session("PropertyConnection"))
    3.             Dim cm As New SqlClient.SqlCommand("", cn)
    4.             Dim ds1 As New DataSet
    5.             Dim strPsn As String
    6.  
    7.  
    8.             sdaData.SelectCommand.Connection = cn
    9.             sdaData.SelectCommand.CommandText = "select * from [orders] where customer = '" & strWhatever & "' order by orderdate desc"
    10.             sdaData.Fill(ds1)
    11.  
    12.             Dim objPds As New PagedDataSource
    13.             objPds.DataSource = ds1.Tables(0).DefaultView
    14.             objPds.AllowPaging = True
    15.             objPds.PageSize = 5  'sets number of pages to display
    16.             Dim CurPage As Integer
    17.             If Len(Request("Page")) > 0 Then
    18.                 CurPage = CInt(Request("Page"))
    19.             Else
    20.                 CurPage = 1
    21.             End If
    22.             objPds.CurrentPageIndex = CurPage - 1
    23.             lblCurrentPage.Text = "Page: " & CurPage.ToString() & " of " & objPds.PageCount.ToString()
    24.  
    25.             If Not (objPds.IsFirstPage) Then
    26.                 lnkPrev.NavigateUrl = "mypage.aspx?page=" & CStr(CurPage - 1)
    27.             End If
    28.             If Not objPds.IsLastPage Then
    29.                 lnkNext.NavigateUrl = "mypage.aspx?page=" & CStr(CurPage + 1)
    30.             End If
    31.  
    32.             Repeater1.DataSource = objPds
    33.             Repeater1.DataBind()
    34.         End If

    It should be very simple to do the same for a datalist.
    SCUZ

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] Paging with a datarepeater

    The best place for this kind of code is the code bank.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width