Before some days i was wondering and trying how to do paging in repeater control. Fortunately i got that quickly. here is the code.
Code Behind. It can be written a s a seperate function and can be called that will be better
'Declaring a shared variable for paging.
Shared pgNum As Integer
'Creating an object of type pageddatasource
Dim pgdata As New PagedDataSource
'Assigning the dataset to paged datasource
pgdata.DataSource = articleSet.DefaultView
'Assigning the pageddatasource properties
pgdata.AllowPaging = True
pgdata.PageSize = LPP.Model.ConstData.PageSizeCommon
pgdata.CurrentPageIndex = pgNum
'Getting the page number
Dim vcnt As Decimal = CDec(count / pgdata.PageSize)
vcnt = Decimal.Ceiling(vcnt)
'Making the navigation buttons visible and invisible.
'Making next button visible when page number greater than 1
If vcnt > LPP.Model.ConstData.One Then
Me.LbtNext.Visible = True
Else
Me.LbtNext.Visible = False
End If
'Making the previous button visible
If pgNum < LPP.Model.ConstData.One Then
Me.LbtPrev.Visible = False
ElseIf pgNum > LPP.Model.ConstData.Zero Then
Me.LbtPrev.Visible = True
If pgNum + LPP.Model.ConstData.One >= vcnt Then
Me.LbtNext.Visible = False
ElseIf pgNum < vcnt Then
Me.LbtNext.Visible = True
End If
End If
'Assigning the pageddatasource to the repeater control
Me.RepArticleSearch.DataSource = pgdata
'Binding the repeater control
Me.RepArticleSearch.DataBind()
For Next Button
Private Sub LbtNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LbtNext.Click
'Incrementing the page number.
pgNum = pgNum + LPP.Model.ConstData.One
Me.GetArticle()
End Sub
For Previous Button
Private Sub LbtPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LbtPrev.Click
'Decrementing the page number.
pgNum = pgNum - LPP.Model.ConstData.One
Me.GetArticle()
End Sub
Asp.net Code For Repeater Control
<asp:Repeater ID="RepArticleSearch" runat="server">
<SeparatorTemplate>
<table width="100%">
<tr>
<td align="center">
<asp:Image ID="ImgSeperator" runat="server" ImageUrl="~/Blogging_Images/side-border.png" />
</td>
</tr>
</table>
</SeparatorTemplate>
<ItemTemplate>
<table width="100%" align="center" class="TableBack">
<tr>
<td width="40%" colspan="2">
<asp:Label ID="LblTitle" runat="server" Text='<%# Eval("TITLE") %>' CssClass="LblTitles"></asp:Label>
</td>
</tr>
<tr>
<td width="15%">
<asp:Label ID="LblPostDate" runat="server" Text='<%# Eval("POSTDATE") %>' CssClass="LblDateAuth"></asp:Label>
</td>
<td align="right">
<asp:Label ID="LblCategoryText" runat="server" meta:resourcekey="LblCategoryText"
CssClass="LblDateAuth"></asp:Label>
<asp:Label ID="LblCategory" runat="server" Text='<%# Eval("CATEGORY") %>' CssClass="LblDateAuth"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="LblDescription" runat="server" Text='<%# Eval("DESCRIPTION") %>' CssClass="LblDescriptionSearch"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>