Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net Gridview, 1 record span two rows

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?

like image 441
Steve McCall Avatar asked Oct 28 '09 15:10

Steve McCall


2 Answers

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>
like image 75
Kevin Avatar answered Nov 03 '22 10:11

Kevin


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>
like image 24
PhilPursglove Avatar answered Nov 03 '22 10:11

PhilPursglove