How to implement paging on repeater control in asp.net

How to implement paging on repeater control
The user should be able to browser pages like below

Page 1 , 2 , 3 ... Next

I would really appreciate any code samples

Thanks
<asp:Repeater ID="productRepeater" runat="server" OnItemDataBound="productRepeater_ItemDataBound">
                            <HeaderTemplate>
                                <table class="sv-products">
                                    <tr>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <td>
                                        <asp:PlaceHolder ID="phResultDetail" runat="server">
                                            <h2>
                                                <asp:Literal ID="ltBrand" runat="server" /></h2>
                                            <asp:HyperLink ID="productUrl2" CssClass="product_name" runat="server" />
                                            <p>
                                                <asp:Literal ID="SearchDisplayPrice" runat="server" />
                                                <asp:Literal ID="ltPromoText" runat="server" />
                                            </p>
                                        </asp:PlaceHolder>
                                    </div>
                                </td>
                            </ItemTemplate>
                            <FooterTemplate>
                            </FooterTemplate>
                        </asp:Repeater>

Open in new window

LVL 1
shieldguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

strickddCommented:
0
muktouCommented:
if you use the ASP.Net 3.5 then ASP.Net's Pager control is usefull for paging in the reaper. if you are not use ASP.Net 3.5 then you should do customazation for the page in Footer Template with Linkbutton.
0
Faheem ShaikhCommented:
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

shieldguyAuthor Commented:
I am a bit confused that which is the best solution as you can see in the attach picture how the page nunmbers are comming and there is also a ... if pages are more than 6

User can click on individual page numbers as well

What is the best way to achieve that above task

Thanks
paging.JPG
0
HainKurtSr. System AnalystCommented:
create a user control with

* current page
* max page
* url

so this control creates links the way you need, and put this on top of your repeater.
set url to the current page, or leave blank (you may need to test it), and check the current page of this control, and filter your repeater data before binding...
 
0
shieldguyAuthor Commented:
if you could provide a sample code or example it would really help me to work faster
0
Faheem ShaikhCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shieldguyAuthor Commented:
faheem29484 i had tried ur code and its giving error now

If the record number greater than page size, it doesn't work. Also there is no NEXT,Previous, First and Last record option

please help
0
HainKurtSr. System AnalystCommented:
I have a simple code which you can extent in any way you want...

(in this example no prev-next or midlle dots... it is easy, just add some more codes in page_load event of ser control)
' put these into your page
<%@ Register Src="~/app/Sample/Pager.ascx" TagName="pager" TagPrefix="uc" %>
 
<uc:pager runat=server Current_Page=1 Page_Number=10 url="" />
' put these into your page
 
----------------------------------------
' create a suser control like this
Partial Class app_Sample_Pager
    Inherits System.Web.UI.UserControl
 
	Private _page_number As Integer
	Property Page_Number() As Integer
		Get
			Return _page_number
		End Get
		Set(ByVal value As Integer)
			_page_number = value
		End Set
	End Property
 
	Private _current_page As Integer = 1
	Property Current_Page() As Integer
		Get
			Return _current_page
		End Get
		Set(ByVal value As Integer)
			_current_page = value
		End Set
	End Property
 
	Private _url As String = ""
	Property url() As String
		Get
			Return _url
		End Get
		Set(ByVal value As String)
			_url = value
		End Set
	End Property
 
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Current_Page = IIf(Request("Page") = "", 1, CInt(Request("Page")))
		Dim i As Integer = 0
		Dim lnk As HyperLink
		For i = 1 To Page_Number
			If i <> Current_Page Then
				lnk = New HyperLink
				lnk.Text = i
				lnk.NavigateUrl = "?page=" & i
				divPager.Controls.Add(lnk)
			Else
				divPager.Controls.Add(New LiteralControl(i))
			End If
			divPager.Controls.Add(New LiteralControl(" | "))
		Next
	End Sub
End Class

Open in new window

Pager.gif
0
HainKurtSr. System AnalystCommented:
a bit extended version... added previous - next buttons (not shown if page is 1 or the last page)

Partial Class app_Sample_Pager
    Inherits System.Web.UI.UserControl
 
	Private _page_number As Integer
	Property Page_Number() As Integer
		Get
			Return _page_number
		End Get
		Set(ByVal value As Integer)
			_page_number = value
		End Set
	End Property
 
	Private _current_page As Integer = 1
	Property Current_Page() As Integer
		Get
			Return _current_page
		End Get
		Set(ByVal value As Integer)
			_current_page = value
		End Set
	End Property
 
	Private _url As String = ""
	Property url() As String
		Get
			Return _url
		End Get
		Set(ByVal value As String)
			_url = value
		End Set
	End Property
 
	Private Function CreateLink(ByVal title As String, ByVal url As String, Optional ByVal alt As String = "") As HyperLink
		Dim lnk As New HyperLink
		lnk.Text = title
		lnk.NavigateUrl = url
		Return lnk
	End Function
 
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Current_Page = IIf(Request("Page") = "", 1, CInt(Request("Page")))
		Dim i As Integer = 0
 
		If Current_Page <> 1 Then
			divPager.Controls.Add(CreateLink(" << ", "?page=" & Current_Page - 1, "Previous Page"))
			divPager.Controls.Add(New LiteralControl(" | "))
		End If
 
		For i = 1 To Page_Number
			If i = Current_Page Then
				divPager.Controls.Add(New LiteralControl("<u><b>" & i & "</b></u>"))
			Else
				divPager.Controls.Add(CreateLink(i, "?page=" & i, "Page " & i))
			End If
			divPager.Controls.Add(New LiteralControl(" | "))
		Next
 
		If Current_Page <> Page_Number Then
			divPager.Controls.Add(CreateLink(" >> ", "?page=" & Current_Page + 1, "Next Page"))
		End If
 
	End Sub
End Class

Open in new window

0
shieldguyAuthor Commented:
But at which stage I bind it to my data?
0
shieldguyAuthor Commented:
Can you please give example that how I filter the data before binding it with the repeater
0
shieldguyAuthor Commented:
I think there is something serioulsy wrong with the expert exchange point based system all I did is to select the award multiple points then its ask for my reason to close question which i did and now it says my last comment is the accepted solution which I never wanted to do

I hope expert exchange should solve this issue as this make me and expert unhappy

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.