GridView数据源为空时显示表头方法
2012-11-09 21:00
393 查看
通常我们用Gridview绑定数据时会先判断数据源是否为空,如果为空则不绑定,那么此时页面将不会显示表格,如果希望在没有数据的情况下依然显示表头,该如何实现呢?
EmptyDataTemplate——空数据模板是GridView控件的属性之一。EmptyDataTemplate表示当记录为空时显示的定义内容。它用来获取或设置在GridView 控件绑定到不包含任何记录的数据源时,在GridView.控件上所显示的空数据行的内容,这个内容可以根据需要来设置。
<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>
序号
</th>
<th>
姓名
</th>
<th>
年龄
</th>
</tr>
</table>
</EmptyDataTemplate>
<Columns>
<asp:BoundField HeaderText="序号" DataField="ID" />
<asp:BoundField HeaderText="姓名" DataField="Name" />
<asp:BoundField HeaderText="年龄" DataField="Age" />
</Columns>
</asp:GridView>
EmptyDataTemplate——空数据模板是GridView控件的属性之一。EmptyDataTemplate表示当记录为空时显示的定义内容。它用来获取或设置在GridView 控件绑定到不包含任何记录的数据源时,在GridView.控件上所显示的空数据行的内容,这个内容可以根据需要来设置。
<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>
序号
</th>
<th>
姓名
</th>
<th>
年龄
</th>
</tr>
</table>
</EmptyDataTemplate>
<Columns>
<asp:BoundField HeaderText="序号" DataField="ID" />
<asp:BoundField HeaderText="姓名" DataField="Name" />
<asp:BoundField HeaderText="年龄" DataField="Age" />
</Columns>
</asp:GridView>
相关文章推荐
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- GridView绑定数据源,无记录时表头也显示的一种解决方法
- 在GridView数据源为空时也显示表头
- 数据源为空时让GridView显示表头和提示
- GridView显示带有中国式报表表头的方法
- 当数据源为空时,gridview只显示表头
- gridview无数据行时显示表头的方法
- asp.net 2.0 中引入的GridView控件当其数据源为空时(GridView.DataSource=null)不能显示出表头-转
- gridview 绑定数据为空时,表头部分内容显示的解决方法
- 在GridView数据源为空时也显示表头
- 如何在数据源是空的时候,gridview显示表头(万能)
- GridView当数据源为空时仍显示表头
- gridview无数据行时显示表头的方法
- 在GridView数据源为空时也显示表头