How to create thead and tbody in ASP.NET Table ?

后端 未结 2 1104
时光说笑
时光说笑 2020-12-01 18:14

How to create thead and tbody in ASP.NET Table? I need those tags because of jquery and asp.net gives me only tr, th and td.

2条回答
  •  感动是毒
    2020-12-01 18:44

    Frédéric's answer is not accurate. asp:Table DOES in fact support and tags, but in a less obvious fashion than HtmlTable.

    UseAccessibleHeader is true by default for tables, which means your header rows will be rendered properly with instead of , but to get the and tags, you've just got to set some voodoo at Page_Load and when you're creating/inserting your rows in the codebehind.

    Here's my example asp:Table markup:

    
        
            Column 1
            Column 2
            Column 3
            Column 4
            Column 5
        
    
    

    At Page_Load, we specify that our TableHeaderRow1 should be a TableHeader:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TableHeaderRow1.TableSection = TableRowSection.TableHeader      
    End Sub
    

    And finally, in your function that inserts rows into said table, you just have to specify that the TableRowSection of each row you add is a TableBody:

    Dim row As TableRow
    Dim dvRow As Data.DataRowView
    
    For Each dvRow In dv
        row = New TableRow
        row.TableSection = TableRowSection.TableBody 'THIS is the important bit
        cell = New TableCell
        Col1Stuff = New Label
        Col1Stuff.Text = "Blah"
        cell.Controls.Add(Col1Stuff)
        row.Cells.Add(cell)
    
        ...
    
    tblGeneral.Rows.Add(row)
    Next
    

    You can do more reading on the TableRowSection property; looks like you can also accomplish this with your asp:Table template.

提交回复
热议问题