Solved

ASP.NET Custom Datagrid Header

Posted on 2004-08-18
11
424 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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