我看过一些其他关于如何实现此功能的帖子...但是,它们似乎都不关心您将 GridView 子类化为您自己的自定义服务器控件的情况。
我试图设置这些属性以使 GridView 呈现 thead 元素,但我不断收到空引用异常。有接受者吗?
这是 DataBind 方法被重写
new public void DataBind()
{
base.DataBind();
UseAccessibleHeader = true;
HeaderRow.TableSection = TableRowSection.TableHeader; //<<-- NRE here
FooterRow.TableSection = TableRowSection.TableFooter;
}
我希望将此逻辑封装在 GridView 控件内,而不是在外部设置。我们正在尝试更新此行为,如果我们采用这种方法,则必须添加代码以在一千个不同的地方进行设置。
显然预渲染事件是放置此事件的最佳位置。诀窍是,在某些我无法理解的情况下,HeaderRow 属性将为 null,因此我只需要检查 null =(
private void MakeAccessible()
{
if (HeaderRow != null && !AllowPaging)
{
UseAccessibleHeader = true;
HeaderRow.TableSection = TableRowSection.TableHeader;
FooterRow.TableSection = TableRowSection.TableFooter;
}
}
protected override void OnPreRender(EventArgs e)
{
MakeAccessible();
}
哈哈,我之前没有想到有时它是空的,有时它不是......doh
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)