有没有办法让DataGrid控件呈现tbody和thead HTML元素?
虽然我喜欢"user186197"的答案,但该博客文章使用反射,但在非完全信任的托管环境中可能会出错.这是我们使用的,没有黑客:
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); } }