Creating an ASP.NET Table Title Bar

I do not know why this does not work. I am trying to create a table header section from end code, but everything goes to tbody.

Dim output As New Web.UI.WebControls.Table 'Create the header row Dim hRow As New Web.UI.WebControls.TableHeaderRow hRow.TableSection = Web.UI.WebControls.TableRowSection.TableHeader hRow.Controls.Add(New Web.UI.WebControls.TableHeaderCell) For Each d As GridDate In Dates Dim hCell As New Web.UI.WebControls.TableHeaderCell hCell.Text = d.Value hRow.Controls.Add(hCell) Next output.Controls.Add(hRow) 

The result is anything you want, despite creating a title bar and setting the section property to the title. What am I doing wrong?

enter image description here

+1
source share
2 answers

An error has occurred in the code I posted. In the last line of my code, I added a new line to the collection of controls:

 output.Controls.Add(hRow) 

Do not do this. It seems to have circumvented some of the properties unique to ASP.NET TableRows in the end. In this case, he ignored the TableSection property, even though it was set correctly. Instead, you should add rows to the row collection:

 output.Rows.Add(hRow) 
0
source

try it

 Dim output As New Table Dim hRow As New TableHeaderRow For Each d As GridDate In Dates Dim hCell As New TableHeaderCell hCell.Text = d.Value hCell.Scope = TableHeaderScope.Column hRow.Cells.Add(hCell) Next output.Rows.Add(hRow) 

It worked for me

0
source

Source: https://habr.com/ru/post/1446214/


All Articles