Is there a way to get the DataGrid control to render the tbody and thead HTML elements?
While I like the answer by "user186197", that blog post uses reflection, things might go wrong in non-full-trusted hosting environments. Here's what we use, no hacks:
public class THeadDataGrid : System.Web.UI.WebControls.DataGrid
{
protected override void OnPreRender(EventArgs e)
{
this.UseAccessibleHeader = true; //to make sure we render TH, not TD
Table table = Controls[0] as Table;
if (table != null && table.Rows.Count > 0)
{
table.Rows[0].TableSection = TableRowSection.TableHeader;
table.Rows[table.Rows.Count - 1].TableSection = TableRowSection.TableFooter;
}
base.OnPreRender(e);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With