当前位置:编程学习 > asp >>

当Gridview没有数据 显示表头

  在开发的时候,很多时候都要用到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="width: 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="学生姓名" />

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,