Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated If e.Row.RowType = DataControlRowType.Header Then 'Build custom header. Dim objGridView As GridView = CType(sender, GridView) Dim objHeaderRow As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert) Dim objCell As TableCell = New TableCell()
Private Sub NewRenderMethod(ByVal writer As HtmlTextWriter, ByVal ctl As Control) ' 'We(don) 't need to write the tag, because(it) 's already written by the writer ' 'so now we write the column ' writer.Write("Name\n") Dim str As String str = "VESTING" _ + "RELEASE" _ + "PAYOUT" writer.Write(str)
' 'The Age column must have the rowspan attribute ' 'and must be rendered inside the ' 'first row so it will centered vertically ' Dim cell As TableCell = CType(ctl.Controls(ctl.Controls.Count - 1), TableCell) ' cell.Attributes.Add("rowspan", "2") ' cell.RenderControl(writer)
''//*** Now we close the first row, so we can insert the second one writer.Write("")
'//*** Add the style attributes that was defined in design time '// to our second row so they both will have the same appearance GridViewRules.HeaderStyle.AddAttributesToRender(writer)
'//*** Insert the second row writer.RenderBeginTag("TR")
' '//*** Render all the cells that was defined ' '// in design time, except the last one ' '// because we already rendered it above ' For i As Int16 = 0 To ctl.Controls.Count - 2 Step 1 ' ctl.Controls(i).RenderControl(writer) ' Next
'//*** We don't need to write the close tag '// because the writer will do that for us '// and so we're done :)
End Sub
Protected Sub GridViewRules_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewRules.RowCreated If e.Row.RowType = DataControlRowType.Header Then e.Row.SetRenderMethodDelegate(New RenderMethod(AddressOf NewRenderMethod)) End If End Sub
Sample for Add Header to existing Header
ReplyDeleteProtected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If e.Row.RowType = DataControlRowType.Header Then
'Build custom header.
Dim objGridView As GridView = CType(sender, GridView)
Dim objHeaderRow As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)
Dim objCell As TableCell = New TableCell()
'Add Header
objCell.Text = "Vesting"
objCell.ColumnSpan = 4
objCell.HorizontalAlign = HorizontalAlign.Center
objHeaderRow.Cells.Add(objCell)
objCell = New TableCell()
objCell.BackColor = Drawing.Color.Black
objHeaderRow.Cells.Add(objCell)
objCell = New TableCell()
objCell.Text = "Release"
objCell.ColumnSpan = 4
objCell.HorizontalAlign = HorizontalAlign.Center
objHeaderRow.Cells.Add(objCell)
objCell = New TableCell()
objCell.BackColor = Drawing.Color.Black
objHeaderRow.Cells.Add(objCell)
objCell = New TableCell()
objCell.Text = "Payout"
objCell.ColumnSpan = 6
objCell.HorizontalAlign = HorizontalAlign.Center
objHeaderRow.Cells.Add(objCell)
'Add new header to GridView
objGridView.Controls(0).Controls.AddAt(0, objHeaderRow)
End If
End Sub
Overwrite Header with new delegate
ReplyDeletePrivate Sub NewRenderMethod(ByVal writer As HtmlTextWriter, ByVal ctl As Control)
' 'We(don) 't need to write the tag, because(it) 's already written by the writer
' 'so now we write the column
' writer.Write("Name\n")
Dim str As String
str = "VESTING" _
+ "RELEASE" _
+ "PAYOUT"
writer.Write(str)
' 'The Age column must have the rowspan attribute
' 'and must be rendered inside the
' 'first row so it will centered vertically
' Dim cell As TableCell = CType(ctl.Controls(ctl.Controls.Count - 1), TableCell)
' cell.Attributes.Add("rowspan", "2")
' cell.RenderControl(writer)
''//*** Now we close the first row, so we can insert the second one
writer.Write("")
'//*** Add the style attributes that was defined in design time
'// to our second row so they both will have the same appearance
GridViewRules.HeaderStyle.AddAttributesToRender(writer)
'//*** Insert the second row
writer.RenderBeginTag("TR")
str = "SeqDateAmountStatus" _
+ "SeqDateAmountStatus" _
+ "SeqAssetDateAmount" _
+ "StatusTaxPayment"
writer.Write(str)
' '//*** Render all the cells that was defined
' '// in design time, except the last one
' '// because we already rendered it above
' For i As Int16 = 0 To ctl.Controls.Count - 2 Step 1
' ctl.Controls(i).RenderControl(writer)
' Next
'//*** We don't need to write the close tag
'// because the writer will do that for us
'// and so we're done :)
End Sub
Protected Sub GridViewRules_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewRules.RowCreated
If e.Row.RowType = DataControlRowType.Header Then
e.Row.SetRenderMethodDelegate(New RenderMethod(AddressOf NewRenderMethod))
End If
End Sub