我正在尝试向 Gridview 添加新的标题行。此行应出现在原始标题行下方。
据我所知,我有两个活动可供选择:
1.) Gridview_RowDataBound 2.) Gridview_RowCreated
选项 1 不是一个选项,因为网格没有绑定每个回发的数据。选项 2 无法按预期工作。我可以添加该行,但它是在 HeaderRow 之前添加的,因为在此事件中尚未添加 HeaderRow 本身......
请帮忙,谢谢!
代码:(InnerTable 属性由自定义 gridview 公开)
Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.Header Then
Dim r As New GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal)
For Each c As DataControlField In CType(sender, GridView).Columns
Dim nc As New TableCell
nc.Text = c.AccessibleHeaderText
nc.BackColor = Drawing.Color.Cornsilk
r.Cells.Add(nc)
Next
Dim t As Table = GridView1.InnerTable
t.Controls.Add(r)
End If
End Sub