Solved

ASP.NET Custom Datagrid Header

Posted on 2004-08-18
11
385 Views
Last Modified: 2010-04-07
Hi,

I have a datagrid and i would like to have a custom header as i need two rows of headers with some of the top cells merged:

---------------------------------------------------------------
      Code                       ||              Name                 |
---------------------------------------------------------------
        ID        |      Det     ||        ID        |        Det      |
---------------------------------------------------------------

Hope you get the idea!!  Is this possible and if so how?

Thanks,
Michael
0
Comment
Question by:Xavior2K3
11 Comments
 
LVL 28

Expert Comment

by:mmarinov
Comment Utility
Hi,

as i know you can not do that
but you can do that with a repeater control
<HeaderTemplate>
    <table>
        <tr>
            <td colspan=2">Code</td>
        </tr>

in the Item template
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "ID")%></td>
<td><%# DataBinder.Eval(Container.DataItem, "Det")%></td>
</tr>

Regards,
B..M
0
 
LVL 3

Expert Comment

by:alexpreston
Comment Utility
If you really want to user a datagrid then you could do it by creating your own custom control that inherits from the datagrid. Then you can override the render method so that when it writes the header row you write a second row also.
But I suspect you don't want to do that!!!
0
 
LVL 1

Accepted Solution

by:
EugeneTrukhin earned 500 total points
Comment Utility
Actually, recently I had the same kind of problem which I solved in the following EASY way:

 Private Sub yourGRID_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles yourGRID.ItemCreated

        If e.Item.ItemType = ListItemType.Header Then
            Dim dgItem As DataGridItem

            Dim dgCell1 As TableCell
            Dim dgCell2 As TableCell
         
            dgItem = New DataGridItem(0, 0, ListItemType.Header)

            dgCell1 = New TableCell
            dgCell1.ColumnSpan =2
            dgItem.Cells.Add(dgCell1)
            dgCell1.Text = "Code"

            dgCell2 = New TableCell
            dgCell2.ColumnSpan = 2
            dgItem.Cells.Add(dgCell2)
            dgCell2.Text = "Name"

            yourGRID.Controls(0).Controls.AddAt(0, dgItem)
        End If

    End Sub

This code is self-explanatory. Tell me if it is not clear.
0
 
LVL 1

Author Comment

by:Xavior2K3
Comment Utility
Hi, that looks pretty easy, nice! Ill try it and give you some feedback!
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Expert Comment

by:EugeneTrukhin
Comment Utility
What's up?

I found pretty good links explaining some theory behind this problem:

http://www.codeproject.com/aspnet/DatagridSeparator.asp

http://www.extremeexperts.com/Net/Articles/ExtendingDataGrid.aspx
0
 
LVL 9

Expert Comment

by:hismightiness
Comment Utility
Why not have an HTMLTable above the datagrid like you would with a "scrollable datagrid w/fixed header"?

http://www.dnzone.com/ShowDetail.asp?NewsId=564
0
 
LVL 6

Expert Comment

by:vardium
Comment Utility
0
 
LVL 3

Expert Comment

by:nitrogenx
Comment Utility
I recommend full points go to EugeneTrukhin, I had this exact same problem recently and his answer is exactly what I've been looking for.  It also seems that this is the answer Xavior2K3 used, from his comments.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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