Is there a way to access the field header name of a databound repeater within the header template. So insted of this....
<HeaderTemplate>
<table >
<th ></th>
<th >Forename</th>
<th >Surname</th>
<th >work email</th>
<th ></th>
</HeaderTemplate>
We get something like this.
<HeaderTemplate>
<table >
<th ></th>
<th ><%# Eval("Forename").HeaderName%></th>
<th ><%# Eval("SureName").HeaderName%></th>
<th ><%# Eval("WorkEmail").HeaderName%></th>
<th ></th>
</HeaderTemplate>
You could move the table header into your ItemTemplate like this:
<ItemTemplate>
<asp:Panel runat="server" Visible='<%# Container.DisplayIndex == 0 %>'>
<tr>
<th><%# Eval("Forename").HeaderName %></th>
</tr>
</asp:Panel>
<tr>
<td><%# Eval("Forename") %></td>
</tr>
</ItemTemplate>
although this is slightly wasteful since the header would be bound for each row (only the first shown though). Perhaps it would be better to use <% if (...) %> instead of a Panel but I don't know how to access the Container.DisplayIndex in that context.
Edit:
In .net 4.5 Container.DisplayIndex
does not work; replace with Container.ItemIndex
.
Full example:
<ItemTemplate>
<asp:Panel runat="server" Visible='<%# Container.ItemIndex == 0 %>'>
<tr>
<th><%# Eval("Forename").HeaderName %></th>
</tr>
</asp:Panel>
<tr>
<td><%# Eval("Forename") %></td>
</tr>
</ItemTemplate>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With