Link to home
Start Free TrialLog in
Avatar of bigbridge
bigbridge

asked on

Have multiple lines (or rows) in header in DataGrid - C#

Hi,

Question...
How can I have multiple lines (or rows) in header in DataGrid?
For example, I want to display like...

                           |       Quantity Sold       |      Quantity Available   |
Product | Customer | Date1 | Date2 | Date3 | Date1 | Date2 | Date3 |

Thanks for your help!

bigbridge
Avatar of raj3060
raj3060
Flag of United States of America image

Easy,
<table border="1" align="center">
<tr>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td>Quantity Sold</td>
<td>Quantity Available</td>
</tr>
<tr>
<td>Product</td>
<td>Customer</td>
<td>
<table>
<tr>
<td>Date1</td>
<td>Date2</td>
<td>Date3</td>
</tr></table>
</td>
<td>
<table>
<tr>
<td>Date1</td>
<td>Date2</td>
<td>Date3</td>
</tr></table>
</td>
</tr>
</table>

--Raj
Here is another way to do it:

<table cellspacing="0" cellpadding="0" border="1" align="center">
<tr>
<td>Product</td>
<td>Customer</td>
<td>
<table cellspacing="0" cellpadding="0" border="1" align="center">
<tr>
<td colspan="3" align="center">Quantity Sold</td>
</tr>
<tr>
<td>Date1</td>
<td>Date2</td>
<td>Date3</td>
</tr></table>
</td>
<td>
<table cellspacing="0" cellpadding="0" border="1" align="center">
<tr>
<td colspan="3" align="center">Quantity Available</td>
</tr>
<tr>
<td>Date1</td>
<td>Date2</td>
<td>Date3</td>
</tr></table>
</td>
</tr>
</table>
Avatar of bigbridge
bigbridge

ASKER

I am using DataGrid in .NET...
I wish I could just use the table though :)
ASKER CERTIFIED SOLUTION
Avatar of raj3060
raj3060
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I still can't find the solution...
From your original post, I assume you already have a datasource specified for the datatable?

Try this...

<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False">
      <Columns>
            <asp:TemplateColumn HeaderText="Quantity Sold">
                  <ItemTemplate>
                        <table cellpadding="0" cellspacing="0">
                              <tr>
                                    <td nowrap>
                                          <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Date1") %>' Width="40" ID="Label1"></asp:Label>
                                          <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Date2") %>' Width="40" ID="Label2"></asp:Label>
                                          <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Date3") %>' Width="40" ID="Label3"></asp:Label>
                                    </td>
                              </tr>
                        </table>
                  </ItemTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn HeaderText="Quantity Available">
                  <ItemTemplate>
                        <table cellpadding="0" cellspacing="0">
                              <tr>
                                    <td nowrap>
                                          <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Date1") %>' Width="40" ID="Label4"></asp:Label>
                                          <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Date2") %>' Width="40" ID="Label5"></asp:Label>
                                          <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Date3") %>' Width="40" ID="Label6"></asp:Label>
                                    </td>
                              </tr>
                        </table>
                  </ItemTemplate>
            </asp:TemplateColumn>
      </Columns>
</asp:DataGrid>

note: I added the table inside the template to allow you to specify 'nowrap' on the <TD>

Please let us know if you have other questions,

Roger
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Point split