VB.NET - GRIDVIEW COLUMN MERGE - Asked By VIDYA on 27-Aug-13 05:12 AM

  
I have a gridview with 11 columns am adding 2 dynamic columns based on 1 condition .
2 columns i added columnspan 2

now i please see the image and help me

thanks in advance

 Protected Sub gvachievers_rowcreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.Header Then


            'Creating a gridview object            
            Dim objGridView As GridView = DirectCast(sender, GridView)

            'Creating a gridview row object
            Dim objgridviewrow As New GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert)

            'Creating a table cell object
            Dim objtablecell As New TableCell()

            'Add a blank cell at the first two cell headers(i.e. User Id & Name

            AddMergedCells(objgridviewrow, objtablecell, 11, String.Empty) 'earlier 8
            '     AddMergedCells(objgridviewrow, objtablecell, 2, String.Empty)
            'Add a blank cell 
            ' AddMergedCells(objgridviewrow, objtablecell, 1, String.Empty)

            addtargetdt = DirectCast(ViewState("target"), DataTable)
            If addtargetdt.Rows.Count > 0 Then
                For i As Integer = 0 To addtargetdt.Rows.Count - 1

                    If (addtargetdt.Rows.Count > 1) Then
                        Dim headertext As String = "Fortnight " & addtargetdt.Rows(i)("ct_target_fn_from").ToString() & "To  " & addtargetdt.Rows(i)("ct_target_fn_to").ToString()
                        AddMergedCells(objgridviewrow, objtablecell, 2, headertext)
                       
                    
                        objtablecell = New TableCell()
                        objtablecell.Text = "Incentive"
                        objtablecell.ForeColor = System.Drawing.Color.White
                        objtablecell.Font.Bold = True
                        objtablecell.RowSpan = 2
                        objgridviewrow.Cells.Add(objtablecell)

                        objtablecell = New TableCell()
                        objtablecell.Text = "IVP"
                        objtablecell.RowSpan = 2
                        objtablecell.ForeColor = System.Drawing.Color.White
                        objtablecell.Font.Bold = True

                        objgridviewrow.Cells.Add(objtablecell)
                    End If

                Next
            End If
            '
            objGridView.Controls(0).Controls.AddAt(0, objgridviewrow)
        End If
    End Sub