shieldguy
asked on
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
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>
Have you tried this: http://www.4guysfromrolla.com/articles/081804-1.aspx
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.
ASKER
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
User can click on individual page numbers as well
What is the best way to achieve that above task
Thanks
paging.JPG
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...
* 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...
ASKER
if you could provide a sample code or example it would really help me to work faster
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
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)
(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
Pager.gif
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
ASKER
But at which stage I bind it to my data?
ASKER
Can you please give example that how I filter the data before binding it with the repeater
ASKER
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
I hope expert exchange should solve this issue as this make me and expert unhappy
Thanks