I'm having trouble creating a Gridview
that can span 2 rows for each record.
I've tried using a templateField
with headerTemplate
and itemTemplates
as separate tables, but I can't get them to format correctly.
Does anybody know of an easier solution for this problem?
Yeah, don't use the GridView. A GridView is used to display tabular data. What you want doesn't fit that criteria. You could use a repeater however my preference is the new in 3.5 ListView
<asp:ListView ID="ListView1" runat="server" >
<ItemTemplate>
<tr>
<td>
<%# Eval("Something") %>
</td>
</tr>
<tr>
<td>
<%# Eval("SomethingElse") %>
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<div>
No data was returned.</td>
</div>
</EmptyDataTemplate>
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server">
</LayoutTemplate>
</asp:ListView>
Have you considered using a Repeater instead of a GridView? The Repeater is probably the easiest way to have 2 rows per record, you get more control over the tabular markup that gets generated e.g.
<asp:Repeater runat="server" ID="Repeater1" >
<HeaderTemplate>
<table>
<tr>
<th>Field 1</th>
</tr>
<tr>
<th>Field 2</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "field1") %></td>
</tr>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "field2") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
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