小TIPS:合拼gridview的header
在asp.net 2.0中的gridview中,有时需要合拼某一行的头部,就是说,比如有三列的表格,那么第一行的表格头可能占满三列了,这就
要合拼gridview的header了.今天看到了一个办法,故分享之,其实就是在row_created事件中编写代码,
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
Dim oCell As New TableCell
oCell.ColumnSpan = e.Row.Cells.Count
e.Row.Cells.Clear()
oCell.Text = "Merged header"
e.Row.Cells.Add(oCell)
End If
End Sub
可以看到,当发现rowtype 为header时,就充分利用单元格的ColumnSpan属性,将其设置为列数的个数,然后去掉原来的内容,在赋值文字就可以拉
要合拼gridview的header了.今天看到了一个办法,故分享之,其实就是在row_created事件中编写代码,
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
Dim oCell As New TableCell
oCell.ColumnSpan = e.Row.Cells.Count
e.Row.Cells.Clear()
oCell.Text = "Merged header"
e.Row.Cells.Add(oCell)
End If
End Sub
可以看到,当发现rowtype 为header时,就充分利用单元格的ColumnSpan属性,将其设置为列数的个数,然后去掉原来的内容,在赋值文字就可以拉