Paging In Repeater Control

Posted by Dotnetrajanikanth under ASP.NET category on | Points: 40 | Views : 2238
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
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

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

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

End Sub Code For Repeater Control

<asp:Repeater ID="RepArticleSearch" runat="server">
<table width="100%">
<td align="center">
<asp:Image ID="ImgSeperator" runat="server" ImageUrl="~/Blogging_Images/side-border.png" />
<table width="100%" align="center" class="TableBack">
<td width="40%" colspan="2">
<asp:Label ID="LblTitle" runat="server" Text='<%# Eval("TITLE") %>' CssClass="LblTitles"></asp:Label>
<td width="15%">
<asp:Label ID="LblPostDate" runat="server" Text='<%# Eval("POSTDATE") %>' CssClass="LblDateAuth"></asp:Label>
<td align="right">
<asp:Label ID="LblCategoryText" runat="server" meta:resourcekey="LblCategoryText"
<asp:Label ID="LblCategory" runat="server" Text='<%# Eval("CATEGORY") %>' CssClass="LblDateAuth"></asp:Label>
<td colspan="2">
<asp:Label ID="LblDescription" runat="server" Text='<%# Eval("DESCRIPTION") %>' CssClass="LblDescriptionSearch"></asp:Label>

Comments or Responses

Login to post response