开发者

change gridview to render thead element

开发者 https://www.devze.com 2023-02-16 00:25 出处:网络
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.

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.

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?

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

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 开发者_如何学Pythonto set this up in a thousand different places if we took that approach.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消