Solved

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

Posted on 2004-09-17
11
283 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:bigbridge
  • 4
  • 2
  • 2
11 Comments
 
LVL 11

Expert Comment

by:raj3060
ID: 12086907
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
0
 
LVL 11

Expert Comment

by:raj3060
ID: 12086964
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>
0
 

Author Comment

by:bigbridge
ID: 12086966
I am using DataGrid in .NET...
I wish I could just use the table though :)
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 11

Accepted Solution

by:
raj3060 earned 125 total points
ID: 12087393
Here are some resources for tasks similar to yours:

http://www.dotnet247.com/247reference/System/Windows/Forms/DataGrid/__discussions/130

Hope this helps
0
 

Author Comment

by:bigbridge
ID: 12087465
I still can't find the solution...
0
 
LVL 1

Expert Comment

by:Roger3
ID: 12088930
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
0
 
LVL 1

Assisted Solution

by:Roger3
Roger3 earned 125 total points
ID: 12221486
Did you get what you needed?

Thanks,
Roger
0
 
LVL 11

Expert Comment

by:raj3060
ID: 12515032
Point split
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now