Empty page header in Gridview while loading page in VB.NET RRS feed

  • Question

  • User-1578974752 posted

    I have a gridview in my asp.net webpage.

    I could show the header even if there is no values in grid viee by showheaderwhen Empty to True.

    When I laod the page ,the header is not showing ,If I click on a button or change the dropdownlist value,,then only the empty header is showing. How can I show an empty gridview header while page loading time? Appreciate the help

    Tuesday, November 13, 2018 1:50 AM

All replies

  • User-893317190 posted

    Hi shsu,

    You say you could show the header when set ShowHeaderWhenEmpty to true.

    After, you say when you load page , the header is not showing.

    I'm confused.

    I have made a test .When setting ShowHeaderWhenEmpty to true,it shows header well.

    Below is my code.

     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="item_id" DataSourceID="SqlDataSource1"  ShowHeaderWhenEmpty="true" >
                <Columns >
                    <asp:BoundField DataField="item_id" HeaderText="item_id" InsertVisible="False" ReadOnly="True" SortExpression="item_id" />
                    <asp:BoundField DataField="item_name" HeaderText="item_name" SortExpression="item_name" />
                    <asp:BoundField DataField="content" HeaderText="content" SortExpression="content" />

    If it is not your case, could you show your sample code to let us reproduce your problem?

    Best regards,

    Ackerly Xu

    Wednesday, November 14, 2018 2:22 AM
  • User-1716253493 posted

    I guess you need to provide datasource and call databind in not ispostback page_load, because the datasource containing column names.

    Or like another post, you can add columns manualy

    Wednesday, November 14, 2018 2:35 AM