Solving your problem will require three different repeaters, one of which is nested inside the other. Start with this markup.
<table> <tr class="headerRow"> <td> </td> <asp:Repeater ID="rptYearHeader" runat="server" OnItemDataBound="rptYearHeader_ItemDataBound"> <ItemTemplate> <td class="header"><asp:Literal ID="litYear" runat="server"></asp:Literal></td> </ItemTemplate> </asp:Repeater> </tr> <asp:Repeater ID="rptName" runat="server" ItemDataBound="rptName_ItemDataBound"> <ItemTemplate> <tr> <td><asp:Literal ID="litName" runat="server"></asp:Literal></td> <asp:Repeater ID="rptAmounts" runat="server" OnItemDataBound="rptAmounts_ItemDataBound"> <ItemTemplate> <td><asp:Literal ID="litAmount" runat="server"></asp:Literal></td> </ItemTemplate> </asp:Repeater> </tr> </ItemTemplate> </asp:Repeater> </table>
Attachment to this can be a bit complicated. The idea is that we first bind the header row and then bind the data rows and columns. You will want to handle the data binding using the code behind, using the OnItemDataBound event, so that you can attach a nested relay with the necessary data.
First, we associate the title bar with Years. You need to select a collection of unique years present in your data source and store it in a private variable. You will need to access it while linking the data of other repeaters later. This will serve as a data source for the title bar, creating one cell / column for each year.
List<DateTime> _Years = dataSource.SelectMany(x => x.data).GroupBy(y => y.Year); rptYear.DataSource = _Years; rptYear.DataBind();
Now you need to associate the Name repeater with the original data source. Something like
rptName.DataSource = dataSource; rptName.DataBind();
This will create one line for each item in your list.
During the OnItemDataBound event for this repeater, you need to bind the nested repeater to the list of fiscal years — one for each fiscal year in our _Years variable — with any applicable data from the current row data item. This is a bit complicated, but I will try to explain:
protected void rptName_ItemDataBound(object sender, RepeaterItemEventArgs e) {
Good luck.
I had to defer this with a few nested repeaters for totals and large totals rows. I began to see nested repeaters in a dream.
Ben elder
source share