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

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

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

ExpandedBlockStart.gif 代码
 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 = " 学生姓名 "   />
27                                           < asp:BoundField DataField = " DetermineStuNo "  HeaderText = " 学号 "   />
28                                           < asp:CommandField HeaderText = " 删除 "  ShowDeleteButton = " True "   />
29                                       </ Columns >
30                                   </ asp:GridView >

 

转载于:https://www.cnblogs.com/LeeYongze/archive/2010/01/24/1655402.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值