views:

430

answers:

2

I have a datasource which contains dated items per row. These will be bound to the repeater and ordered by date. I'd like to present each month as a seperate table when rendered but is there a way to do this with a repeater control without having to have multiple repeaters added dynamically from the server side code?

Ideally I'd like the following:

Examples Data:

Row 1: Title 1, 01/12/2009
Row 2: Title 1, 02/12/2009
Row 1: Title 1, 01/01/2010
Row 1: Title 1, 02/01/2009

Required output:

Dec 09
-------------------------------
Title  |  Date                 |
-------------------------------|
Title1 |  01/12/2009           |
-------------------------------|
Title2 |  02/12/2010           |
-------------------------------|

Jan 10
-------------------------------
Title  |  Date                 |
-------------------------------|
Title1 |  01/01/2010           |
-------------------------------|
Title2 |  02/01/2010           |
-------------------------------|
A: 

Your example data and your output do not match, but I think I know what you are going for here.

I would work this out to get 1 set of data to bind into the main repeater, this would be your "Dec 09" and "Jan 10" data. Inside the item template have another repeater, defined once, and simply use the "OnDataBound" event to load data to the second repeater.

It is simple, effective and easy to manage.

Mitchel Sellers
+1  A: 

You can use PlaceHolder controls within the ItemTemplate to contain the repeating goup headers and footers. Then set the visibility of the PlaceHolders in the OnItemDataBound or OnItemCreated event handlers based on the dates. Like this:

<ItemTemplate>

<asp:PlaceHolder id="table_end" visible="<%# _newMonthStarting && (!_firstMonth) %>" runat="server">
  </table>
</asp:PlaceHolder>

<asp:PlaceHolder id="table_end" visible="<%# _newMonthStarting %>" runat="server">
  <div><%# _monthHeader</div>
  <table>
    <tr>
      <th>Title</th>      
      <th>Date</th>      
    </tr>
</asp:PlaceHolder>
  <tr>
    <td><!-- data --></td>
    <td><!-- data --></td>
  </tr>
</ItemTemplate>

<FooterTemplate>
   </table>
</FooterTemplate>
Ray
Cheers, this looks like the most straight forward way to implement this. I'd hoped that there was some mechanism of the repeater that I wasn't aware of which would avoid server side code but this looks good.
Brian Scott