Paging in Repeater Control in VB.Net

Recently I came across a Requirement where I was needed to add the Paging functionality to the repeater Control because the repeater control didn't have the built in functionality for paging.

One can achieve so by following the below mentioned process:

At the source code add the following code :

<asp:Repeater ID="rptXYZ" runat="server">
..........Your repeter content
</Asp:Repeater >
<table>
<tr>
<td><asp:button id="cmdPrev" runat="server" text=" << "></asp:button> </td>
<td> <asp:Panel id="PnlNumber" runat="server"></asp:Panel> </td>
<td> <asp:button id="cmdNext" runat="server" text=" >> "></asp:button> </td>
</tr>
</table>

Here a panel is added to insert a link button dynamically. At the code behind, add the following code :

At gobal declaration


Dim objPds As New PagedDataSource

Create one property as

Public Sub showPagination()

   Dim XYZDS As New DataSet

   XYZDS = Session("XYZDS")

   '' Populate the repeater control with the Items DataSet

 

   If Not XYZDS Is Nothing Then

       If Not (XYZDS.Tables("Table1") Is Nothing) Then

           Dim ilnkno As Double

           Dim Pagerpagesize As Integer

           Pagerpagesize = 3      

  '' (any) Number of record to show at one go

           ilnkno = XYZDS.Tables("Table1").Rows.Count / Pagerpagesize

  '' ilnkno is Number of link buttons to add

            ilnkno = Math.Ceiling(ilnkno)

    

            For index As Integer = 1 To ilnkno

               Dim lnkbtn As New LinkButton

                lnkbtn.Text = index

                                       

               lnkbtn.ID = "lnkbtn" + index.ToString()

               AddHandler lnkbtn.Click, AddressOf lnkbtn_Click

               PnlNumber.Controls.Add(lnkbtn)

            Next

            objPds.DataSource = XYZDS.Tables("Table1").DefaultView

            '' Indicate that the data should be paged

            objPds.AllowPaging = True

            '' Set the number of items you wish to display per page must be same

            ''as Pagerpagesize                        

            objPds.PageSize = 3

            objPds.CurrentPageIndex = CurrentPage - 1

             '' CurrentPage  is property to set index                

            Repeterxyz.Datasource= objPds    

             ' Binding paged data to repeter       

            End If

        End If

End Sub

Note

 
Dynamically created controls may disappear on the post back, you require to call the pagination function on the init/load event as per the requirement.
Next Recommended Reading How to Generate Log in VB.NET