ASP.NET 2.0 - DataGrid与tbody / thead [英] ASP.NET 2.0 - DataGrid with tbody / thead

查看:222
本文介绍了ASP.NET 2.0 - DataGrid与tbody / thead的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

当我喜欢这个文件的时候,有没有办法让DataGrid控件渲染tbody和HTML元素?通过user186197回答,该博客使用反射,在非完全受信任的主机环境中可能会出现问题。这是我们使用的,没有黑客:

  public class THeadDataGrid:System.Web.UI.WebControls.DataGrid 
{
protected override void OnPreRender(EventArgs e)
{
this.UseAccessibleHeader = true; //确保我们呈现TH,而不是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);
}
}


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);
    }
}

这篇关于ASP.NET 2.0 - DataGrid与tbody / thead的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆