GridView woes.

Today, I was extending the GridView control to support some customization for our ADF framework, when I ran into the following error:

The table  must contain row sections in order of header, body, then footer.

This error occurred after I had enabled paging. On first hand, it seemed to me that this error was purely bad design, and the results I found on the internet seem to support that thought (e.g. this post).

So I did what other people also tried:

protected override void OnInit(EventArgs e)
{
    UseAccessibleHeader = true;
    base.OnInit(e);
}

and

protected override void OnRowCreated(GridViewRowEventArgs e)
{
    switch (e.Row.RowType)
    {
        case DataControlRowType.Header:
            e.Row.TableSection = TableRowSection.TableHeader;
            break;
        case DataControlRowType.Footer:
            e.Row.TableSection = TableRowSection.TableFooter;
            break;
    }
}

Since the default TableSection is TableBody, we can skip that one. This seems to work, as long as paging is disabled. The code above will take care of nice wrapped table content in <thead>, <tbody> and <tfoot> tags.

So why is this not working when you enable paging? Apparently .NET adds another section somewhere, and it’s TableSection property has a value which it shouldn’t have. The solution is simple: the RowType of the pager is not Footer, but Pager.

The following code will fix the error, and result in the pager being part of the <tfoot> node:

        case DataControlRowType.Footer:
        case DataControlRowType.Pager:
            e.Row.TableSection = TableRowSection.TableFooter;

 

0 Responses to “GridView woes.”


  • No Comments

Leave a Reply