When we bind data with the gridview, we first determine whether the data source is empty. If it is empty, it is not bound. Then the page will not display the table, if you want to display the table header without data, how can this problem be achieved?
Emptydatatemplate -- An Empty data template is one of the properties of the gridview control. Emptydatatemplate indicates the definition content displayed when the record is empty. It is used to obtain or set the content of the blank data row displayed on the gridview. control when the gridview control is bound to a data source that does not contain any records. This content can be set as needed.
<Asp: gridview id = "gridview1" runat = "server" autogeneratecolumns = "false" width = "200px"
Borderwidth = "0" backcolor = "# ddbbdd">
<Emptydatatemplate>
<Table cellspacing = "0" style = "border-collapse: collapse; width: 100%; Background-color: red;
Margin:-1px ">
<Tr>
<TH>
Serial number
</Th>
<TH>
Name
</Th>
<TH>
Age
</Th>
</Tr>
</Table>
</Emptydatatemplate>
<Columns>
<Asp: boundfield headertext = "no." datafield = "ID"/>
<Asp: boundfield headertext = "name" datafield = "name"/>
<Asp: boundfield headertext = "Age" datafield = "Age"/>
</Columns>
</ASP: gridview>