65.9K
CodeProject is changing. Read more.
Home

Merge DataGrid Header

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.67/5 (3 votes)

May 4, 2012

CPOL
viewsIcon

20546

This is an alternative for "Merge DataGrid Header"

Introduction

Another way to is to handle the ItemDataBound event. 

Background

You want to do colspan on a DataGrid header.

Using the code

Catch ItemDataBound. Test for the header. You can also do colspan tricks to data rows.

Private Sub AreaGrid_ItemDataBound(ByVal sender As Object, _
        ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
        Handles AreaGrid.ItemDataBound
    If e.Item.ItemType = ListItemType.Header Then
     
        'remove third cell and extend the second cell 
            e.Item.Cells.RemoveAt(2)
            e.Item.Cells(1).ColumnSpan = 2
          
        Return 
    End If
End Sub