GridView動態新增RowCell

GridView動態新增RowCell

 

01 Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
02         If e.Row.RowType = DataControlRowType.Header Then
03             Dim ogridview As GridView = CType(sender, GridView)
04             Dim ogirdviewrow As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)
05             Dim otablecell As TableCell = New TableCell
06
07             'add department
08             otablecell.Text = "Department"
09             otablecell.ColumnSpan = 3
10             ogirdviewrow.Cells.Add(otablecell)
11
12             'add employee
13             otablecell = New TableCell
14             otablecell.Text = "Employee"
15             otablecell.ColumnSpan = 2
16             ogirdviewrow.Cells.Add(otablecell)
17             ogridview.Controls(0).Controls.AddAt(0, ogirdviewrow)
18
19         End If
20     End Sub