Repeated Headers in a Repeater

Discussion in 'ASP .Net' started by Robert Walter, Apr 26, 2004.

  1. 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.



    Rob.


    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
    {
    get
    {
    return _headerRepeatRows;
    }
    set
    {
    _headerRepeatRows = value;
    }
    }

    public Repeater()
    {
    this.ItemCreated += new
    RepeaterItemEventHandler(GroupingRepeater_ItemCreated);
    }

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

    HeaderTemplate.InstantiateIn(header);

    this.Controls.Add(header);

    _repeatedRows = 0;
    }

    _repeatedRows++;
    }
    }
    }
    }
     
    Robert Walter, Apr 26, 2004
    #1
    1. Advertisements

  2. Robert Walter

    srinivas091

    Joined:
    Oct 7, 2013
    Messages:
    1
    Likes Received:
    0
    Hi Robert,

    This is excellent code. It had helped me a lot. Thanks a lot.

    Regards,
    Srinivas
     
    srinivas091, Oct 7, 2013
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Replies:
    0
    Views:
    1,243
  2. Replies:
    0
    Views:
    3,333
  3. Replies:
    1
    Views:
    7,382
    Karl Seguin
    Aug 10, 2005
  4. dont bother
    Replies:
    0
    Views:
    1,215
    dont bother
    Mar 3, 2004
  5. uncensored
    Replies:
    0
    Views:
    1,139
    uncensored
    Oct 25, 2006
  6. Phil
    Replies:
    4
    Views:
    1,169
    Gabriel Genellina
    Jan 17, 2010
  7. Ian
    Replies:
    2
    Views:
    3,140
  8. Microsoft

    Repeater inside a Repeater

    Microsoft, Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    466
    Microsoft
    Aug 21, 2006
Loading...