469,625 Members | 1,091 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

coolness of repeater - with paging?

Hi guys

Just developing a cool list that pulls data from an SQL database. I've got a
nice header, a footer, borders down the side, but no top/bottom borders for
the rows, and onmouseover / onmouseout commands to "rollover" the rows.

Looks great - then I've realised I can't page it. Grr!! It looks like I have
to use DataGrid (??) to get paging, although that doesn't support the
Templatates (again, ??).

Just looking for suggestions on how to implement my cool list thing really.
Have I missed something? ny ideas appreciated!

Cheers
Dan
Nov 18 '05 #1
1 1421
You have to implement your own custom paging with a repeater. The difficult
part arises from actually doing the paging of your datasource. DataGrid
achieves this by doing it all on the client (web server) which can be a real
performance killer for high-stress applications. You can use a control like
the following to actually display paging information (prev 1 2 3 4 5 next)
and expose events when a page is changed, but again you'll need to figure
out how best to bind your datasource:

using System;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Utility {
public class Pager : WebControl, IPostBackEventHandler {
#region Fields and Properties
public int CurrentPage {
get {
if (ViewState["CurrentPage"] == null) {
return 1;
}
return Convert.ToInt32(ViewState["CurrentPage"],
CultureInfo.InvariantCulture);
}
set { ViewState["CurrentPage"] = value; }
}
public int TotalItems {
get {
if (ViewState["TotalItems"] == null) {
return 1;
}
return Convert.ToInt32(ViewState["TotalItems"],
CultureInfo.InvariantCulture);
}
set { ViewState["TotalItems"] = value; }
}
public int ItemsPerPage {
get {
if (ViewState["ItemsPerPage"] == null) {
return 1;
}
return Convert.ToInt32(ViewState["ItemsPerPage"],
CultureInfo.InvariantCulture);
}
set { ViewState["ItemsPerPage"] = value; }
}
public event CommandEventHandler PageClick;
#endregion

private void OnPageClick(object sender, CommandEventArgs e) {
if (PageClick != null) {
PageClick(sender, e);
}
}
protected override void Render(HtmlTextWriter writer) {
if (Page != null) {
Page.VerifyRenderingInServerForm(this);
}
base.Render(writer);
}
protected override void RenderContents(HtmlTextWriter writer) {
int totalPages = (int)Math.Ceiling(TotalItems / ItemsPerPage);

if (totalPages == 1 || totalPages == 0) {
return;
}
if (CurrentPage > 1) {
writer.AddAttribute(HtmlTextWriterAttribute.Href,
Page.GetPostBackClientHyperlink(this, (CurrentPage -
1).ToString(CultureInfo.InvariantCulture)));
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID
+ ":prev");
writer.RenderBeginTag(HtmlTextWriterTag.A);
writer.Write("prev");
writer.RenderEndTag();
writer.Write(HtmlTextWriter.SpaceChar);
}

for (int i = 1; i <= totalPages; ++i) {
string page = i.ToString(CultureInfo.InvariantCulture);
if (i == CurrentPage) {
writer.RenderBeginTag(HtmlTextWriterTag.B);
writer.Write(page);
writer.RenderEndTag();
writer.Write(HtmlTextWriter.SpaceChar);
} else {
writer.AddAttribute(HtmlTextWriterAttribute.Href,
Page.GetPostBackClientHyperlink(this, page));
writer.AddAttribute(HtmlTextWriterAttribute.Name,
this.UniqueID + ":" + page);
writer.RenderBeginTag(HtmlTextWriterTag.A);
writer.Write(page);
writer.RenderEndTag();
writer.Write(HtmlTextWriter.SpaceChar);
}
}
if (CurrentPage < totalPages) {
writer.AddAttribute(HtmlTextWriterAttribute.Href,
Page.GetPostBackClientHyperlink(this, (CurrentPage +
1).ToString(CultureInfo.InvariantCulture)));
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID
+ ":next");
writer.RenderBeginTag(HtmlTextWriterTag.A);
writer.Write("next");
writer.RenderEndTag();
writer.Write(HtmlTextWriter.SpaceChar);
}
}
public void RaisePostBackEvent(string eventArgument) {
CurrentPage = Convert.ToInt32(eventArgument,
CultureInfo.InvariantCulture);
CommandEventArgs e = new CommandEventArgs("PageClick",
eventArgument);
OnPageClick(this, e);
}
}
}
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:46**********************************@microsof t.com...
Hi guys

Just developing a cool list that pulls data from an SQL database. I've got a nice header, a footer, borders down the side, but no top/bottom borders for the rows, and onmouseover / onmouseout commands to "rollover" the rows.

Looks great - then I've realised I can't page it. Grr!! It looks like I have to use DataGrid (??) to get paging, although that doesn't support the
Templatates (again, ??).

Just looking for suggestions on how to implement my cool list thing really. Have I missed something? ny ideas appreciated!

Cheers
Dan

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mark | last post: by
1 post views Thread by Pums | last post: by
8 posts views Thread by Matthew Curiale | last post: by
1 post views Thread by ratnakarp | last post: by
3 posts views Thread by NullQwerty | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.