Multi row header in Datagrid

Discussion in 'ASP .Net Datagrid Control' started by William Gower, May 17, 2004.

  1. I have two columns in my datagrid, Hours Bid and Hours Expense. I would
    like to have the word Hours span both columns and then just have the column
    headings Bid and Expense underneath. Is that possible and how do I do that?
     
    William Gower, May 17, 2004
    #1
    1. Advertising

  2. Hi William,

    During the PreRender event you can create a new datagrid header item. Add
    one cell to it and tell the cell to span two columns. Add that to the
    header. Insert this as the first item of the datagrid Here's some code:

    Private Sub DataGrid1_PreRender _
    (ByVal sender As Object, _
    ByVal e As System.EventArgs) _
    Handles DataGrid1.PreRender
    ' Spans columns in an ASP.NET datagrid header
    ' Ken Cox Microsoft MVP [ASP.NET]
    Dim dgitem As New DataGridItem _
    (0, 0, ListItemType.Header)
    Dim tblCell As New TableCell
    tblCell.ColumnSpan = 2
    tblCell.Text = "Hours"
    dgitem.Cells.Add(tblCell)
    DataGrid1.Controls(0).Controls.AddAt _
    (0, dgitem)
    End Sub

    Does this help?

    Ken
    Microsoft MVP [ASP.NET]


    "William Gower" <> wrote in message
    news:...
    >I have two columns in my datagrid, Hours Bid and Hours Expense. I would
    > like to have the word Hours span both columns and then just have the
    > column
    > headings Bid and Expense underneath. Is that possible and how do I do
    > that?
    >
    >
     
    Ken Cox [Microsoft MVP], May 17, 2004
    #2
    1. Advertising

  3. Thanks it almost works. I want it to appear over the 8 and 9th columns in
    the header. Which value do I change for it to do that?

    "Ken Cox [Microsoft MVP]" <> wrote in message
    news:%...
    > Hi William,
    >
    > During the PreRender event you can create a new datagrid header item. Add
    > one cell to it and tell the cell to span two columns. Add that to the
    > header. Insert this as the first item of the datagrid Here's some code:
    >
    > Private Sub DataGrid1_PreRender _
    > (ByVal sender As Object, _
    > ByVal e As System.EventArgs) _
    > Handles DataGrid1.PreRender
    > ' Spans columns in an ASP.NET datagrid header
    > ' Ken Cox Microsoft MVP [ASP.NET]
    > Dim dgitem As New DataGridItem _
    > (0, 0, ListItemType.Header)
    > Dim tblCell As New TableCell
    > tblCell.ColumnSpan = 2
    > tblCell.Text = "Hours"
    > dgitem.Cells.Add(tblCell)
    > DataGrid1.Controls(0).Controls.AddAt _
    > (0, dgitem)
    > End Sub
    >
    > Does this help?
    >
    > Ken
    > Microsoft MVP [ASP.NET]
    >
    >
    > "William Gower" <> wrote in message
    > news:...
    > >I have two columns in my datagrid, Hours Bid and Hours Expense. I would
    > > like to have the word Hours span both columns and then just have the
    > > column
    > > headings Bid and Expense underneath. Is that possible and how do I do
    > > that?
    > >
    > >

    >
     
    William Gower, May 17, 2004
    #3
  4. Hi William,

    You just need to add some more dummy cells before the span. You could use
    the same technique for adding dummy cells after the span.

    Ken

    Private Sub DataGrid1_PreRender _
    (ByVal sender As Object, _
    ByVal e As System.EventArgs) _
    Handles DataGrid1.PreRender
    ' Spans columns in an ASP.NET datagrid header
    ' Ken Cox Microsoft MVP [ASP.NET]
    Dim intCounter As Integer
    Dim dgitem As New DataGridItem _
    (0, 0, ListItemType.Header)
    Dim tblCell As TableCell
    ' Pad cells before the spanning cell
    ' Adjust the count as necessary
    For intCounter = 0 To 6
    tblCell = New TableCell
    tblCell.ColumnSpan = 1
    tblCell.Text = "&nbsp;"
    dgitem.Cells.Add(tblCell)
    Next
    tblCell = New TableCell
    tblCell.ColumnSpan = 2
    tblCell.Text = "Hours"
    dgitem.Cells.Add(tblCell)
    DataGrid1.Controls(0).Controls.AddAt _
    (0, dgitem)
    End Sub

    "William Gower" <> wrote in message
    news:...
    > Thanks it almost works. I want it to appear over the 8 and 9th columns in
    > the header. Which value do I change for it to do that?
    >
     
    Ken Cox [Microsoft MVP], May 17, 2004
    #4
  5. thank you. It looks great. One small problem though. I have allowpaging.
    But I only show the paging at the bottom of the page.

    When it displays my page, I see the row that displays hours in the proper
    column position, then I see the numeric page numbers then I see the other
    row header.

    Why is my paging showing up between the two rows?

    "Ken Cox [Microsoft MVP]" <> wrote in message
    news:...
    > Hi William,
    >
    > You just need to add some more dummy cells before the span. You could use
    > the same technique for adding dummy cells after the span.
    >
    > Ken
    >
    > Private Sub DataGrid1_PreRender _
    > (ByVal sender As Object, _
    > ByVal e As System.EventArgs) _
    > Handles DataGrid1.PreRender
    > ' Spans columns in an ASP.NET datagrid header
    > ' Ken Cox Microsoft MVP [ASP.NET]
    > Dim intCounter As Integer
    > Dim dgitem As New DataGridItem _
    > (0, 0, ListItemType.Header)
    > Dim tblCell As TableCell
    > ' Pad cells before the spanning cell
    > ' Adjust the count as necessary
    > For intCounter = 0 To 6
    > tblCell = New TableCell
    > tblCell.ColumnSpan = 1
    > tblCell.Text = "&nbsp;"
    > dgitem.Cells.Add(tblCell)
    > Next
    > tblCell = New TableCell
    > tblCell.ColumnSpan = 2
    > tblCell.Text = "Hours"
    > dgitem.Cells.Add(tblCell)
    > DataGrid1.Controls(0).Controls.AddAt _
    > (0, dgitem)
    > End Sub
    >
    > "William Gower" <> wrote in message
    > news:...
    > > Thanks it almost works. I want it to appear over the 8 and 9th columns

    in
    > > the header. Which value do I change for it to do that?
    > >

    >
     
    William Gower, May 17, 2004
    #5
  6. Also what if I want to add a third row header?

    "Ken Cox [Microsoft MVP]" <> wrote in message
    news:...
    > Hi William,
    >
    > You just need to add some more dummy cells before the span. You could use
    > the same technique for adding dummy cells after the span.
    >
    > Ken
    >
    > Private Sub DataGrid1_PreRender _
    > (ByVal sender As Object, _
    > ByVal e As System.EventArgs) _
    > Handles DataGrid1.PreRender
    > ' Spans columns in an ASP.NET datagrid header
    > ' Ken Cox Microsoft MVP [ASP.NET]
    > Dim intCounter As Integer
    > Dim dgitem As New DataGridItem _
    > (0, 0, ListItemType.Header)
    > Dim tblCell As TableCell
    > ' Pad cells before the spanning cell
    > ' Adjust the count as necessary
    > For intCounter = 0 To 6
    > tblCell = New TableCell
    > tblCell.ColumnSpan = 1
    > tblCell.Text = "&nbsp;"
    > dgitem.Cells.Add(tblCell)
    > Next
    > tblCell = New TableCell
    > tblCell.ColumnSpan = 2
    > tblCell.Text = "Hours"
    > dgitem.Cells.Add(tblCell)
    > DataGrid1.Controls(0).Controls.AddAt _
    > (0, dgitem)
    > End Sub
    >
    > "William Gower" <> wrote in message
    > news:...
    > > Thanks it almost works. I want it to appear over the 8 and 9th columns

    in
    > > the header. Which value do I change for it to do that?
    > >

    >
     
    William Gower, May 17, 2004
    #6
  7. Ok I solved this one.

    "William Gower" <> wrote in message
    news:%23%...
    > thank you. It looks great. One small problem though. I have

    allowpaging.
    > But I only show the paging at the bottom of the page.
    >
    > When it displays my page, I see the row that displays hours in the proper
    > column position, then I see the numeric page numbers then I see the other
    > row header.
    >
    > Why is my paging showing up between the two rows?
    >
    > "Ken Cox [Microsoft MVP]" <> wrote in message
    > news:...
    > > Hi William,
    > >
    > > You just need to add some more dummy cells before the span. You could

    use
    > > the same technique for adding dummy cells after the span.
    > >
    > > Ken
    > >
    > > Private Sub DataGrid1_PreRender _
    > > (ByVal sender As Object, _
    > > ByVal e As System.EventArgs) _
    > > Handles DataGrid1.PreRender
    > > ' Spans columns in an ASP.NET datagrid header
    > > ' Ken Cox Microsoft MVP [ASP.NET]
    > > Dim intCounter As Integer
    > > Dim dgitem As New DataGridItem _
    > > (0, 0, ListItemType.Header)
    > > Dim tblCell As TableCell
    > > ' Pad cells before the spanning cell
    > > ' Adjust the count as necessary
    > > For intCounter = 0 To 6
    > > tblCell = New TableCell
    > > tblCell.ColumnSpan = 1
    > > tblCell.Text = "&nbsp;"
    > > dgitem.Cells.Add(tblCell)
    > > Next
    > > tblCell = New TableCell
    > > tblCell.ColumnSpan = 2
    > > tblCell.Text = "Hours"
    > > dgitem.Cells.Add(tblCell)
    > > DataGrid1.Controls(0).Controls.AddAt _
    > > (0, dgitem)
    > > End Sub
    > >
    > > "William Gower" <> wrote in message
    > > news:...
    > > > Thanks it almost works. I want it to appear over the 8 and 9th

    columns
    > in
    > > > the header. Which value do I change for it to do that?
    > > >

    > >

    >
    >
     
    William Gower, May 17, 2004
    #7
  8. Well that's tantalizing!?! I'm running into exactly the same problem.
    I'm glad you've solved it, but HOW?

    Thanks!
    Brad.

    On Mon, 17 May 2004 11:50:00 -0400, "William Gower"
    <> wrote:

    >Ok I solved this one.
    >
    >"William Gower" <> wrote in message
    >news:%23%...
    >> thank you. It looks great. One small problem though. I have

    >allowpaging.
    >> But I only show the paging at the bottom of the page.
    >>
    >> When it displays my page, I see the row that displays hours in the proper
    >> column position, then I see the numeric page numbers then I see the other
    >> row header.
    >>
    >> Why is my paging showing up between the two rows?
    >>
    >> "Ken Cox [Microsoft MVP]" <> wrote in message
    >> news:...
    >> > Hi William,
    >> >
    >> > You just need to add some more dummy cells before the span. You could

    >use
    >> > the same technique for adding dummy cells after the span.
    >> >
    >> > Ken
    >> >
    >> > Private Sub DataGrid1_PreRender _
    >> > (ByVal sender As Object, _
    >> > ByVal e As System.EventArgs) _
    >> > Handles DataGrid1.PreRender
    >> > ' Spans columns in an ASP.NET datagrid header
    >> > ' Ken Cox Microsoft MVP [ASP.NET]
    >> > Dim intCounter As Integer
    >> > Dim dgitem As New DataGridItem _
    >> > (0, 0, ListItemType.Header)
    >> > Dim tblCell As TableCell
    >> > ' Pad cells before the spanning cell
    >> > ' Adjust the count as necessary
    >> > For intCounter = 0 To 6
    >> > tblCell = New TableCell
    >> > tblCell.ColumnSpan = 1
    >> > tblCell.Text = "&nbsp;"
    >> > dgitem.Cells.Add(tblCell)
    >> > Next
    >> > tblCell = New TableCell
    >> > tblCell.ColumnSpan = 2
    >> > tblCell.Text = "Hours"
    >> > dgitem.Cells.Add(tblCell)
    >> > DataGrid1.Controls(0).Controls.AddAt _
    >> > (0, dgitem)
    >> > End Sub
    >> >
    >> > "William Gower" <> wrote in message
    >> > news:...
    >> > > Thanks it almost works. I want it to appear over the 8 and 9th

    >columns
    >> in
    >> > > the header. Which value do I change for it to do that?
    >> > >
    >> >

    >>
    >>

    >
     
    Bradley Plett, Jun 9, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vaidas gudas

    How to make multi-Row header in the datagrid

    vaidas gudas, Jul 8, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,621
    Scott Allen
    Jul 8, 2004
  2. mlt
    Replies:
    2
    Views:
    852
    Jean-Marc Bourguet
    Jan 31, 2009
  3. D
    Replies:
    0
    Views:
    220
  4. AlainCD
    Replies:
    0
    Views:
    206
    AlainCD
    Jan 12, 2006
  5. datagrid having row header and column header

    , Jul 13, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    185
Loading...

Share This Page