views:

41

answers:

3

In a repeater is it possible to have a field only show once and then again if it changes?

What I want it to look like

Audio
 - Thing
 - Thing
 - Thing
Video
 - thing
 - thing
Picture
 - thing

They are going to be ordered by Type either audio video picture but I don't want to have repeat Audio Video Picture as well. Thanks

A: 

What you want is called a control/break report. It's a little odd to do in ASP.Net, but not impossible.

See these:

Joel Coehoorn
A: 

Why not intercept the rowdatabound event in the code behind and use a global variable which has the last Section title then inject an element when it changes such as:

    public partial class _Default : System.Web.UI.Page 
{
    private string LastTitle = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        var title = (string) DataBinder.Eval(e.Item.DataItem,"TypeField");

        if (title != this.LastTitle )
        {
            e.Item.Controls.AddAt(

                0,
                new Literal()
                    {

                        Text = string.Format("<h2>{0}</h2>", title)
                    });
            this.LastTitle = title;
        }
    }
}
Richard
A: 

I have used this set of classes in the past to do grouping and summaries in gridviews. Using the code is very simple involving only a few lines of code to configure.

http://www.agrinei.com/gridviewhelper/gridviewhelper_en.htm

HectorMac