Display the table header when the gridview data source is empty

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.