Repeated Headers in a Repeater


Robert Walter

I was looking for a method to repeat the headers on an ASP.NET
Repeater control. I couldn't find quite what I wanted on the web so I
implemented it myself. I thought it maybe useful for some of you out
there (code is below). It works exactly the same as a normal repeater
except that there is an extra property HeaderRepeatRows in it.

Note, if you use this generate a table then put the <table> tag
outside the header template otherwise it'll be repeated each time the
header is.

A similar method can probably be used to do the same for a datagrid
but it's made a bit more difficult as you have the header
automatically being generated.


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.ComponentModel;

namespace Pjv.Pjo.Controls
/// <summary>
/// Summary description for Repeater.
/// </summary>
public class Repeater : System.Web.UI.WebControls.Repeater
private int _headerRepeatRows = 0;
private int _repeatedRows = 0;

public int HeaderRepeatRows
return _headerRepeatRows;
_headerRepeatRows = value;

public Repeater()
this.ItemCreated += new

private void GroupingRepeater_ItemCreated(object sender,
RepeaterItemEventArgs e)
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
if ((_headerRepeatRows > 0) && (_repeatedRows ==
RepeaterItem header = new RepeaterItem(0, ListItemType.Header);



_repeatedRows = 0;



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question