Solved

ASP.NET Custom Datagrid Header

Posted on 2004-08-18
11
397 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
 
LVL 1

Author Comment

by:Xavior2K3
ID: 11831520
Hi, that looks pretty easy, nice! Ill try it and give you some feedback!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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:vardium
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JavaScript error 1 52
How to access a DataBinder.Eval variable using C# ? 4 27
Vb.net dynamic formulas in runtime 11 61
Ajax Panel Not Updating When Triggered By Timer 4 40
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

15 Experts available now in Live!

Get 1:1 Help Now