Phi*_*ins 186
这应该这样做:
gv.HeaderRow.TableSection = TableRowSection.TableHeader;
小智 24
我在OnRowDataBound事件中使用它:
protected void GridViewResults_OnRowDataBound(object sender, GridViewRowEventArgs e) {
    if (e.Row.RowType == DataControlRowType.Header) {
        e.Row.TableSection = TableRowSection.TableHeader;
    }
}
ASa*_*lvo 10
答案中的代码需要继续Page_Load或GridView_PreRender.我把它放在一个被调用的方法之后Page_Load得到了一个NullReferenceException.
我使用以下代码执行此操作:
if我添加的陈述很重要.
否则(取决于渲染网格的方式),您将抛出以下异常:
该表必须按标题,正文和页脚的顺序包含行部分.
protected override void OnPreRender(EventArgs e)
{
    if ( (this.ShowHeader == true && this.Rows.Count > 0)
      || (this.ShowHeaderWhenEmpty == true))
    {
        //Force GridView to use <thead> instead of <tbody> - 11/03/2013 - MCR.
        this.HeaderRow.TableSection = TableRowSection.TableHeader;
    }
    if (this.ShowFooter == true && this.Rows.Count > 0)
    {
        //Force GridView to use <tfoot> instead of <tbody> - 11/03/2013 - MCR.
        this.FooterRow.TableSection = TableRowSection.TableFooter;
    }
    base.OnPreRender(e);
}
该this对象是我的GridView控件.
我实际上覆盖了Asp.net GridView来制作我自己的自定义控件,但你可以将它粘贴到你的aspx.cs页面并按名称引用GridView而不是使用custom-gridview方法.
仅供参考:我没有测试过页脚逻辑,但我知道这适用于Headers.
小智 5
这对我有用:
protected void GrdPagosRowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.TableSection = TableRowSection.TableBody;
    }
    else if (e.Row.RowType == DataControlRowType.Header)
    {
        e.Row.TableSection = TableRowSection.TableHeader;
    }
    else if (e.Row.RowType == DataControlRowType.Footer)
    {
        e.Row.TableSection = TableRowSection.TableFooter;
    }
}
这是在 VS2010 中尝试过的。
| 归档时间: | 
 | 
| 查看次数: | 54728 次 | 
| 最近记录: |