怎样让gridview没有数据时也显示标题行

jstzcl007 2010-07-05 03:03:28
gridview通过sqldatasource控件显示数据库里的数据,我将sqldatasource的selectquery属性设置成SELECT * FROM [jinhuobiao] where xsh<>'1' and xsh<>'2',这样gridview里不显示数据,等待后面增加数据。
问题是gridview里没有数据时,最上面的标题行也没有了,怎样做到没有数据时也显示标题行?
...全文
672 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
onlylikews 2010-07-05
  • 打赏
  • 举报
回复
插入一条全部为空字符串的数据
dengNeeo 2010-07-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zlchina1989 的回复:]
编辑GridView里面的EmptyDataTemplate,该模板是在GridView没有数据的时候进行显示的模板
[/Quote]
这个是对的



<asp:GridView ID="grvUnsigned" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3" Width="99%" AllowPaging="True"
onpageindexchanging="grvUnsigned_PageIndexChanging">
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<Columns>
<asp:BoundField DataField="角色名" HeaderText="角色名" >
<HeaderStyle Width="50%" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="用户名" HeaderText="用户名" >
<HeaderStyle Width="50%" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Center" />
<EmptyDataTemplate>
<div style=" color:Red; text-align:center; width:100%;">
查询条件内无记录
</div>
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
zlchina1989 2010-07-05
  • 打赏
  • 举报
回复
编辑GridView里面的EmptyDataTemplate,该模板是在GridView没有数据的时候进行显示的模板
ansiboy 2010-07-05
  • 打赏
  • 举报
回复
考虑使用 GridView 的客户端组件吧。http://jdata.alinq.org
teerhu 2010-07-05
  • 打赏
  • 举报
回复
編輯模板列<EmptyDataTemplate>
totodele 2010-07-05
  • 打赏
  • 举报
回复
不要用* 把你要大字段全列出来
hanqing_liu 2010-07-05
  • 打赏
  • 举报
回复
<EmptyDataTemplate>
<tr class="GridViewHeaderStyle">
<th>
<input id="chkAll" type="checkbox" />
</th>
<th>
<asp:Label ID="Label9" runat="server" Text="<%$ Resources:LocalizedText, Inventory_InventoryList_0000009 %>"></asp:Label>
</th>
<th>
<asp:Label ID="Label10" runat="server" Text="<%$ Resources:LocalizedText, Inventory_InventoryList_0000010 %>"></asp:Label>
</th>
<th>
<asp:Label ID="Label11" runat="server" Text="<%$ Resources:LocalizedText, Inventory_InventoryList_0000011 %>"></asp:Label>
</th>
<th>
<asp:Label ID="Label12" runat="server" Text="<%$ Resources:LocalizedText, Inventory_InventoryList_0000012 %>"></asp:Label>
</th>
<th>
<asp:Label ID="Label13" runat="server" Text="<%$ Resources:LocalizedText, Inventory_InventoryList_0000013 %>"></asp:Label>
</th>
</tr>
</EmptyDataTemplate>
baobei7758 2010-07-05
  • 打赏
  • 举报
回复
Gridview空数据的时候显示表头
http://blog.csdn.net/xfblue/archive/2009/02/03/3861242.aspx

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧