GridView应用 当Gridview没有数据 显示表头 TC

  在开发的时候,很多时候都要用到GridView,但是,当GridView没有数据时,GridView就显示不出来。很难看,正好最近做项目用到此方法,就把代码贴出来,供大家学习及自己以后备用。方法很简单,就是在GridView套用一个Table。

  特别要注意此处<td colspan="3"> 没有相关数据 </td>  colspan="3"是批GridView有多少列。

代码
 1 <asp:GridView ID="grvStudentInfo" runat="server" CssClass="listgrid" AutoGenerateColumns="False"
 2                                     AllowSorting="True" DataKeyNames="ID" 
 3                                     OnRowDeleting="grvStudentInfo_RowDeleting" 
 4                                     onrowdatabound="grvStudentInfo_RowDataBound">
 5                                     <EmptyDataTemplate>
 6                                         <table style="text-align: center">
 7                                             <tr>
 8                                                 <th style=" 100px;">
 9                                                     学生姓名
10                                                 </th>
11                                                 <th>
12                                                     学号
13                                                 </th>
14                                                 <th>
15                                                     删除
16                                                 </th>
17                                             </tr>
18                                             <tr align="center">
19                                                 <td colspan="3">
20                                                     没有相关数据
21                                                 </td>
22                                             </tr>
23                                         </table>
24                                     </EmptyDataTemplate>
25                                     <Columns>
26                                         <asp:BoundField DataField="StudentName" HeaderText="学生姓名" />
27                                         <asp:BoundField DataField="DetermineStuNo" HeaderText="学号" />
28                                         <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
29                                     </Columns>
30                                 </asp:GridView>

作者:Mr S.R Lee
出处:http://www.cnblogs.com/LeeYongze
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

原文地址:https://www.cnblogs.com/LeeYongze/p/1655402.html