Solved

ASP.NET Custom Datagrid Header

Posted on 2004-08-18
11
406 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
ID: 11830188
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
ID: 11830233
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
ID: 11830562
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Author Comment

by:Xavior2K3
ID: 11831520
Hi, that looks pretty easy, nice! Ill try it and give you some feedback!
0
 
LVL 1

Expert Comment

by:EugeneTrukhin
ID: 11851067
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
ID: 12069741
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:Volkan Vardar
ID: 12166922
0
 
LVL 3

Expert Comment

by:nitrogenx
ID: 12396287
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web site error 3 36
Initial get page response times and IIS8 15 49
Need help with building query string 2 19
Where did System.Data.Objects go? 2 23
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

816 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

10 Experts available now in Live!

Get 1:1 Help Now