数据源为空GridView显示表头和提示

 方法一:采用GridView中的EmptyTemplate来实现,模版中写一个静态的table;

下面贴出aspx代码:

<head runat="server">
    <title>GridView使用EmptyTemplate来使无数据时显示表头</title>
</head>
<body>
    <form id="form1" runat="server">
    <strong>GridView使用EmptyTemplate来使无数据时显示表头</strong>
    <div>
        <asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1" BackColor="White" BorderColor="#336666" Width="600px"
            BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Horizontal">
            <FooterStyle BackColor="White" ForeColor="#333333" />
            <RowStyle BackColor="White" ForeColor="#333333" />
            <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
            <EmptyDataTemplate>
                <table cellpadding="0" cellspacing="0" width="600px">
                    <tr>
                       <td width="100px">
                          用户编号
                       </td>
                       <td width="100px">
                          用户姓名
                       </td>
                       <td width="100px">
                          用户类型
                       </td>
                       <td width="100px">
                          用户年龄
                       </td>
                       <td width="100px">
                          电子邮件
                       </td>
                       <td width="100px">
                          联系地址
                       </td>
                    </tr>
                    <tr>
                       <td colspan="6" align="center">
                          没有数据显示
                       </td>
                    </tr>
                </table>
            </EmptyDataTemplate>
        </asp:GridView>
   
    </div>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/GridViewTest.mdb"
            SelectCommand="SELECT [UuserID], [UuserName], [UuserPower], [Age], [Email], [Address] FROM [Uuser]">
        </asp:AccessDataSource>
    </form>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值