C# - Repeater Control Paging - Can't Use A Js (templates) / Json Approach
Aug 2, 2010
I've got a repeater control containing comments. I'm about to implement ajax paging to it. I was opting to use the updatepanel (conditionally) for this thing, but I guess it's going to get kinda slow in production environment (Each time about 20 rows will be visible). I want to keep the repeater control since it contains other controls as well so I can't use a js (templates)/json approach.
URL... I'm trying this approach and I like it, It is what i was finding. customize the function he wrote to populate the pager control:Â
private void PopulatePager(int recordCount, int currentPage) { double dblPageCount = (double)((decimal)recordCount / Convert.ToDecimal(PageSize)); int pageCount = (int)Math.Ceiling(dblPageCount); List<ListItem> pages = new List<ListItem>(); if (pageCount > 0)
[code]...
I need the paginator is something like that:<FIRST><BACK>1,2,3....N<NEXT><LAST>where first return back to first page, back go to previous current page, next for next page and last jump to last page.How can I do that?
If I have a custom user control (say, MyCustomControl.ascx) which contains a number of other controls including a repeater, is there any way to expose that repeater's templates as templates for MyCustomControl?
For example, I would want to be able to do this:
[code]....
There could potentially be more than one repeater or other templated controls within the parent control, in which case I would like to be able to expose all of those templates for all of the controls in the same way.
My first thought was to simply expose the repeater's templates as ITemplate properties on MyCustomControl, but that didn't work since there's no (obvious) way to access the repeater's DataItem from the templates doing it that way.
I have dropdown in the aspx page. I am calling JQuery on dropdown chnage and JQuery is calling GenericHandler.ashx . The Handler is retuns Serialize JSON string. I ned to bind my Repeater control with this JOSN object. here I am giving my sample aspx page code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
I am trying to experiment with things as a beginner and want to use paging in Repeater Control. Since Repeater control is light weight, I want to use that. I have heard of two methods: PagedDataSource class and the other that I dont remember. I wanted to attempt both of them. How do I proceed?
I have a strange problem. I have made a PagedRepeater control, which inherits from the Repeater, from a tutorial I saw here: http://www.4guysfromrolla.com/articles/020905-1.aspx. It's in VB and I'm in C#, and it didn't quite have all the features I was lookingfor, so, I've modified it quite a bit. I added support for a SqlDataSource control, as well. The only problem is, that it always returns the first item from the SqlDataSource, even when the CurrentPageIndex on the PagedDataSource is set to a different value.
I have a Custom Repeater control that inherits from Repeater and has paging functionality, however when I click the next page button the first time it refreshes the control but does not change the page, if I click it again after that it changes page perfectly. I know what the issue is, when I click the next button it does a postback, then the data is bound to the repeater, and then after that the NextButton Event is handled.
Is there any way I can change the order of the page load events?? Or force the repeater to reload again after the event is handled?? I've included my Custom Repeater class bellow:
using System.Web.UI.WebControls; using System.Web.UI; using System.Data; using System.Collections; using System; namespace ASPresentation.Controls { [ToolboxData("<cc:PagedRepeater runat=server></cc:PagedRepeater>")] public class PagedRepeater : Repeater { public int PageSize { get; set; } public int CurrentPageIndex { get { return Convert.ToInt16(Page.Session["ProjectIndex"]); } set { Page.Session.Add("ProjectIndex", value); } } public PagedDataSource pagedData = new PagedDataSource(); LinkButton NextBtn = new LinkButton(); LinkButton PrevBtn = new LinkButton(); public bool IsLastPage { get { return pagedData.IsLastPage; } } public bool IsFirstPage { get { return pagedData.IsFirstPage; } } public override object DataSource { get { return base.DataSource; } set { pagedData.DataSource = (IEnumerable)value; } } protected void NextButtonClick(object sender, EventArgs e) { if (!IsLastPage) { CurrentPageIndex++; } } protected void PrevButtonClick(object sender, EventArgs e) { if (!IsFirstPage) { CurrentPageIndex--; } } protected override void OnInit(EventArgs e) { base.OnInit(e); NextBtn.Text = "Next"; PrevBtn.Text = "Prev"; NextBtn.Click += new EventHandler(NextButtonClick); PrevBtn.Click += new EventHandler(PrevButtonClick); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); base.Controls.Add(PrevBtn); base.Controls.Add(NextBtn); } protected override void Render(HtmlTextWriter writer) { base.Render(writer); } public override void DataBind() { pagedData.AllowPaging = true; pagedData.PageSize = PageSize; pagedData.CurrentPageIndex = CurrentPageIndex; base.DataSource = pagedData; base.DataBind(); } } }
I am using a repeater control and i want to use one more repeater control inside the existing repeater control .Â
Like this:
<asp:Repeater ID="Repeater1" runat="server">   <HeaderTemplate> </HeaderTemplate>      <ItemTemplate> <!-- start child repeater -->    Here I want to use one repater control     <!-- end child repeater --> </ItemTemplate> </asp:Repeater>
I have a page on my ASP.NET site that has a Repeater control to show posts from members of the site.
At the moment I am storing the data for the posts in an XML file and then caching it within the site inside custom objects.
So I have:
public class MemberPost { public string Title { get; set; } public string Text { get; set; } public string Name { get; set; } public DateTime Date { get; set; } public List<string> Pictures { get; set; } }
And:
public class MemberPosts : List<MemberPost> { }
I'm able to set the data source of the repeater to an instance of MemberPosts and it all works as expected, but I want to add paging for when more posts are added.
All the examples I find seem to involve having the data to be paged in a database - is there any way I can bind the repeater or another similar control to my in-memory MemberPosts collection and have it implement paging for me?
I've been looking for a good tutorial to teach me how to make a customized Paging control with a simple DataBound control like Repeater to implement a high performance paging feature. I've found a lot of articles about that issue, but non of them was a complete answer. Paging of Large Resultsets in ASP.NET. This one is awesome, with statistics and great comparison between the different methods of doing so, but the problem is it's too old before SQL Server had it's new function ROW_NUMBER() N-Layered Web Applications with ASP.NET 3.5 Part 4: Sorting, Paging and Filtering (The Database Paging Section and ignore the rest)
This one is almost perfect, but he used the grid's existing paging feature with a customized Method for paging, instead of a repeater. Custom SEO friendly paging with ASP.NET Repeater or DataList control I think this one is WAY too complicated, and things can get done easier. I'm using SQL, Items Repeater (with direct binding in the code-behind with no datasources used), PageNumbers repeater (which will have a link as an ItemTemplate to pass querystring so the used method could retrieve the next portion of Items), A Label to hold the current page number and title.
I've been trying to implement the example on N-Layered Web Applications with ASP.NET 3.5 Part 4: Sorting, Paging and Filtering (The Database Paging Section and ignore the rest). So far I've created a SQL command in my Data Access Lyaer that looks like this: WITH Records AS ( SELECT ItemId, ItemName, ROW_NUMBER() OVER ORDER BY ItemId) AS 'RowNumber' FROM Items) SELECT * FROM Records WHERE (RowNumber BETWEEN (@startIndex) AND @startIndex + @pageSize - 1)
I'm doing a webpage with a search that brings a lot of information from MSSQL. What I did is a stored procedure that return only the page to be seen on the website. Right now I'm working on the paging as I need to show something similar than google. If you are at page 1 they show first 10 pages and if you are at page 19 they show since page 9 to 28. I think the best option to show the page numbers is using a linkbutton inside a repeater. The problem that I have now is that I do not know the best way to take the page number at postback.
Doing a quick sample I assigned an ArrayList to repeater.datasource: <asp:Repeater ID="Repeater2" runat="server"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument="<%# Container.DataItem %>"><%# Container.DataItem %></asp:LinkButton> </ItemTemplate> </asp:Repeater> <asp:LinkButton ID="LinkButton2" runat="server" CommandArgument="4654">Test #1</asp:LinkButton>
At my Default.aspx.cs file I have the next code
protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack) { string x = LinkButton2.CommandArgument; //string y = LinkButton1.CommandArgument; //I know this line will not work since the Linkbutton1 is inside the Repeater. }
What Shall I do to make it works? Does anyone has a better solution for this paging?
i am using two tables for salary components like bonus,hra,ta,da.one is salary lookup table for viewing which components are chosen and according to this salary table is created dynamically.i want to view data fields of salary table in gridview and update thier value.
now problem is that how to create template field and edit template field for updating fields of salary table because field of the salary table changing every time as it is creating dynamically.
I have recently found this snippet of code but I am unable to get it to work. Does anybody know if the $index syntax has changed in the latest version of the client templates?
I use prettyPhoto to display images from database. The images are displayed in a Repeater control with paging enabled, and with page size set to 3.
Everything works fine, the gallery loads up, I can go through pictures. But, prettyPhoto loads only 3 pictures at a time. So if I get 12 pictures from the database, I get 4 pages. So every time I have to view pictures from Page1, close the gallery, click the Next button that displays Page2 and so on.
I understand that this is happening because I set the PageSize to 3. I'm not sure how to "tell" prettyPhoto that there are actually more photos.
This is how I bind the Repeater to the datasource:
vb.net Code:
Dim Pds1 as New PagedDataSource()Pds1.DataSource = dsPictures.Tables(0).DefaultViewPds1.AllowPaging = TruePds1.CurrentPageIndex = CurrentPage Repeater3.DataSource = Pds1Repeater3.DataBind
This is the HTML for the page that uses the Repeater and gallery:
vb.net Code:
<a href = '<%#DataBinder.Eval(Container, "DataItem.newsPictureURL")%>' rel="prettyPhoto[Repeater3]" title = '<%#DataBinder.Eval(Container, "DataItem.newsPictureCaption")%><img id="icons" src = '<%#DataBinder.Eval(Container, "DataItem.newsPictureLocation")%>' alt = '<%#DataBinder.Eval(Container, "DataItem.newsPictureDesc")%>' />
As you can see, I use rel="prettyPhoto[Repeater3]" where Repeater3 is the name of the gallery, or DataSource.
I know it is hard to figure out anything with out inspecting the prettyPhoto source (jQuery).