Solved

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

Posted on 2004-09-17
11
281 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
Comment Utility
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
Comment Utility
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
Comment Utility
I am using DataGrid in .NET...
I wish I could just use the table though :)
0
 
LVL 11

Accepted Solution

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

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

Hope this helps
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:bigbridge
Comment Utility
I still can't find the solution...
0
 
LVL 1

Expert Comment

by:Roger3
Comment Utility
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
Comment Utility
Did you get what you needed?

Thanks,
Roger
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Point split
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

771 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

12 Experts available now in Live!

Get 1:1 Help Now