Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 875343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:15:14+00:00 2026-05-15T11:15:14+00:00

From an MSDN article on the subject, we can see that we create a

  • 0

From an MSDN article on the subject, we can see that we create a TableHeaderRowthat contains TableHeaderCells.

But they add the table header like this:

myTable.Row.AddAt(0, headerRow);

which outputs the HTML:

<table id="Table1" ... > 
<tr> 
    <th scope="column" abbr="Col 1 Head">Column 1 Header</th>
    <th scope="column" abbr="Col 2 Head">Column 2 Header</th>
    <th scope="column" abbr="Col 3 Head">Column 3 Header</th> 
</tr>
<tr> 
    <td>(0,0)</td>
    <td>(0,1)</td>
    <td>(0,2)</td>
</tr>

...

and it should have <thead> and <tbody> (so it works seamless with tablesorter) 🙂

<table id="Table1" ... > 
<thead>
<tr> 
    <th scope="column" abbr="Col 1 Head">Column 1 Header</th>
    <th scope="column" abbr="Col 2 Head">Column 2 Header</th>
    <th scope="column" abbr="Col 3 Head">Column 3 Header</th> 
</tr>
</thead>
<tbody>
<tr> 
    <td>(0,0)</td>
    <td>(0,1)</td>
    <td>(0,2)</td>
</tr>
    ...
    </tbody>

the HTML aspx code is

<asp:Table ID="Table1" runat="server" />

How can I output the correct syntax?


Just as information, the GridViewcontrol has this built in as we just need to set the Accesbility and use the HeaderRow

gv.UseAccessibleHeader = true;
gv.HeaderRow.TableSection = TableRowSection.TableHeader;
gv.HeaderRow.CssClass = "myclass";

but the question is for the Table control.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:15:15+00:00Added an answer on May 15, 2026 at 11:15 am

    Just found a way to do this, we do need to use our own controls that inherit from the base control, for example a Table

    public class myTable : System.Web.UI.WebControls.Table
    {
        protected override void OnPreRender(EventArgs e)
        {
            Table table = Controls[0] as Table;
    
            if (table != null && table.Rows.Count > 0)
            {
                // first row is the Table Header <thead>
                table.Rows[0].TableSection = TableRowSection.TableHeader;
                // last row is the Footer Header <tfoot> (comment for not using this)
                table.Rows[table.Rows.Count - 1].TableSection = TableRowSection.TableFooter;
    
                FieldInfo field = typeof(WebControl).GetField("tagKey", BindingFlags.Instance | BindingFlags.NonPublic);
                foreach (TableCell cell in table.Rows[0].Cells)
                    field.SetValue(cell, HtmlTextWriterTag.Th);
            }
            base.OnPreRender(e);
        }
    }
    

    works fine with DataGrid as well

    public class myDataGrid : System.Web.UI.WebControls.DataGrid 
    {
        protected override void OnPreRender(EventArgs e)
        {
            Table table = Controls[0] as Table;
    
            if (table != null && table.Rows.Count > 0)
            {
                // first row is the Table Header <thead>
                table.Rows[0].TableSection = TableRowSection.TableHeader;
                // last row is the Footer Header <tfoot> (comment for not using this)
                table.Rows[table.Rows.Count - 1].TableSection = TableRowSection.TableFooter;
    
                FieldInfo field = typeof(WebControl).GetField("tagKey", BindingFlags.Instance | BindingFlags.NonPublic);
                foreach (TableCell cell in table.Rows[0].Cells)
                    field.SetValue(cell, HtmlTextWriterTag.Th);
            }
            base.OnPreRender(e);
        }
    }
    

    then for example you just need to use it instead the base control:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            myGridView dg = new myGridView();
            dg.DataSource = new string[] { "1", "2", "3", "4", "5", "6" };
            dg.DataBind();
    
            ph.Controls.Add(dg);
        }
    }
    

    and in aspx page, just add a place holder like:

    <asp:PlaceHolder ID="ph" runat="server" />
    

    full example in pastebin

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got the following statement from an MSDN article . It says that the
From the MSDN article on STAThread: Indicates that the COM threading model for an
From the MSDN Article I read I should be using the StringBuilder rather than
From the ASP.Net Page Lifecycle article on MSDN : Although both Init and Load
From MSDN doc : A delegate is a type that safely encapsulates a method,
From MSDN Types that implement IComparable must override Equals.Types that override Equals must also
This example is from the PLINQ MSDN article: http://msdn.microsoft.com/en-us/library/dd997399.aspx var queryA = from num
Given this MSDN article, we learn that the Common Type System in .Net has
This is a XAML code sample taken from the MSDN library article for the
In this MSDN article , it says that In the .NET Framework version 2.0,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.