How do I get Gridview to render THEAD?

前端 未结 8 942
鱼传尺愫
鱼传尺愫 2020-12-04 10:12

How do I get the GridView control to render the tags? I know .UseAccessibleHeaders makes it p

8条回答
  •  心在旅途
    2020-12-04 10:27

    I use the following code to do this:

    The if statements I added are important.

    Otherwise (depending on how you render your grid) you'll throw exceptions like:

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

    protected override void OnPreRender(EventArgs e)
    {
        if ( (this.ShowHeader == true && this.Rows.Count > 0)
          || (this.ShowHeaderWhenEmpty == true))
        {
            //Force GridView to use  instead of  - 11/03/2013 - MCR.
            this.HeaderRow.TableSection = TableRowSection.TableHeader;
        }
        if (this.ShowFooter == true && this.Rows.Count > 0)
        {
            //Force GridView to use  instead of  - 11/03/2013 - MCR.
            this.FooterRow.TableSection = TableRowSection.TableFooter;
        }
        base.OnPreRender(e);
    }
    

    The this object is my GridView.

    I actually overrode the Asp.net GridView to make my own custom control, but you could paste this into your aspx.cs page and reference the GridView by name instead of using the custom-gridview approach.

    FYI: I haven't tested the footer logic, but I do know this works for Headers.

提交回复
热议问题