Add Gridview Row AFTER Header

前端 未结 3 1527
旧时难觅i
旧时难觅i 2021-01-13 01:34

i\'m trying to add a new headerrow to a Gridview. This row should appear below the original headerrow.

As far as I know I have two events to choose from:

1.)

3条回答
  •  醉酒成梦
    2021-01-13 02:02

    Try this when you add the row to the InnerTable:

    t.Controls.AddAt(1, r)
    

    Here's a quick basic test I did, which seems to work OK:

    Protected Sub gridview_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridview.DataBound
        Dim g As GridView = CType(sender, GridView)
    
        Dim r As New GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal)
        Dim th As New TableHeaderCell()
        th.ColumnSpan = g.Columns.Count
        th.Text = "This is my new header"
        r.Cells.Add(th)
    
        Dim t As Table = CType(g.Controls(0), Table)
        t.Rows.AddAt(1, r)
    End Sub
    

提交回复
热议问题