加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET 2.0 – 带有tbody / thead的DataGrid

发布时间:2020-12-16 04:00:19 所属栏目:asp.Net 来源:网络整理
导读:有没有办法让DataGrid控件呈现tbody和thead HTML元素? 解决方法 虽然我喜欢“user186197”的答案,但该博客文章使用反射,但在非完全信任的托管环境中可能会出错.这是我们使用的,没有黑客: public class THeadDataGrid : System.Web.UI.WebControls.DataGrid
有没有办法让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);
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读