Ok, here's a clever (if I may say so) solution:
We nest a repeater inside of a repeater to manually construct the HTML table. The outer repeater (table rows) is bound to the table's columns collection (to pivet the source table columns to output table rows). The inner repeater (of cells) is bound to the rows of the table (to pivet source rows to columns).
We have to construct databinding syntax for the inner repeater to look back out at the bound object of the outer repeater (the source DataTable). This lets us get at the rows of that source table.
While we are looking backwards from the inner repeater we can see the RepeaterItem from the outer repeater that the inner repeater control is inside of. This allows us to see the object (DataColumn) that the outer repeater's RepeaterItem is bound to. Thus we can use this DataColumn to reference the current outer repeater's Column to get the corresponding value from the current row of the inner repeater.
Here's the markup:
<table border="1" cellspacing="0" cellpadding="2">
<asp:repeater runat="server" id="rptRows">
<itemtemplate>
<tr>
<td><%# Container.DataItem.ColumnName%></td>
<asp:repeater runat="server" datasource='<%# Container.DataItem.Table.Rows %>'>
<itemtemplate>
<td><%# CType(Container.DataItem, System.Data.DataRow)(CType(Container.Parent.Parent , RepeaterItem).DataItem) %></td>
</itemtemplate>
</asp:repeater>
</tr>
</itemtemplate>
</asp:repeater>
</table>
Here's a breakdown of the databinding syntax for the data columns (best to look at this in the forum page to get the color coding):
CType(Container.DataItem, System.Data.DataRow)(CType(Container.Parent.Parent , RepeaterItem).
DataItem)
Container: System.Web.UI.WebControls.RepeaterItem (Inner Repeater)
Container.DataItem: DataRow of the table rows iteration
Container.Parent: Inner Repeater
Container.Parent.Parent: System.Web.UI.WebControls.RepeaterItem (Outer Repeater)
CType(Container.Parent.Parent, RepeaterItem).
DataItem: DataColumn (from outer repeater iteration)
This solution will work with any sized table because of the nested repeater.
-
Peter