How to render .NET TableCell as TH instead of TD?

I am dynamically creating a .NET table, including TableRows with a set of TablesSection, resulting in 1 row of THEAD and several rows of TBODY. Now I need to get TableCells in the THEAD line for rendering with TH tags, not TD tags. How should I do it? I did not find the TableCell attribute for it, and this allowed me to add literals to the collection of row cells.

+3
source share
3 answers

Have you tried TableHeaderCell?

+12
source

You can use HtmlGenericControl th = new HtmlGenericControl("th")and add this to thead line.

0
source

TableCell Render.

- WebControl, , .

protected override void Render(HtmlTextWriter writer)
    {
        if (Type == CellType.th)
        {
            writer.Write(HtmlTextWriter.TagLeftChar + "th"); // Render <th
            Attributes.Render(writer); // Render any associated attributes
            writer.Write(HtmlTextWriter.TagRightChar); // Render >
            base.RenderContents(writer); // Render the content between the <th></th> tags
            writer.Write(HtmlTextWriter.EndTagLeftChars + "th" + HtmlTextWriter.TagRightChar); // Render </th>
        }
        else
            base.Render(writer); // Defaults to rendering <td>
    }

This solution allows you to inherit one class, not how TableCelland TableHeaderCellif you want to configure them accordingly.

EDIT

The property Typein the statement ifis a custom property of the class in which I added enumto simplify the applicable types.

public enum CellType
{
    td,
    th
}

private CellType _Type;
public CellType Type
{
    get { return _Type; }
    set { _Type = value; }
}
0
source

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


All Articles