改变GridView控件呈现THEAD元素 [英] change gridview to render thead element

查看:353
本文介绍了改变GridView控件呈现THEAD元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到的是如何得到这个工作的一些其他职位。不过他们都不与您在其中sublcassed GridView控件作为自己的自定义服务器控件的情况下予以关注。

I have seen some other posts on how to get this working ... however none of them seem to be concerned with case where you have sublcassed the GridView as your own custom server control.

我试图设置这些属性来获取GridView控件呈现一个THEAD元素,但我不断地得到一个空引用异常。任何考生?

I am attempting to set these properties to get the GridView to render a thead element but I continually get a null reference exception. Any takers?

下面是我的overrided方法DatBind

Here is the DatBind method I overrided

    new public void DataBind()
    {
        base.DataBind();
        UseAccessibleHeader = true;
        HeaderRow.TableSection = TableRowSection.TableHeader; //<<-- NRE here
        FooterRow.TableSection = TableRowSection.TableFooter;
    }

我想这个逻辑GridView控件内进行封装,而不是外部设置。我们正在努力更新这种行为,就必须添加code在一千个不同的地方设置此,如果我们采取了这种做法。

I want this logic to be encapsulated within the GridView control and not externally set. We are trying to update this behavior and would have to add the code to set this up in a thousand different places if we took that approach.

推荐答案

显然,pre渲染事件是把这个最好的地方。诀窍是,在某些情况下是ellude我来说,HeaderRow属性将为空,因此我只需要检查空=(

Apparently the pre render event is the best place to put this. The trick is that in some circumstances that ellude me, the HeaderRow property will be null so I just needed to check for 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(); 
    }

洛尔没有发生较早,我认为有时候是空,有时不...卫生署

Lol didn't occur earlier to me that sometimes it is null and sometimes it is not ... doh

这篇关于改变GridView控件呈现THEAD元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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