Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.NET Custom Datagrid Header

Posted on 2004-08-18
11
Medium Priority
?
461 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
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 …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

927 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