• GridView数据源为空时显示表头方法


          通常我们用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; 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>

  • 相关阅读:
    Ubuntu下基于Virtualenv构建Python开发环境
    Linux查看用户登录信息-last
    SpringCloud实践引入注册中心+配置中心
    git仓库构建小记
    windows下使用hbase/opencv/ffmpeg小记
    Java执行jar总结
    命名空间
    phpstudy ——composer使用
    template-web.js
    redis
  • 原文地址:https://www.cnblogs.com/qianxingdewoniu/p/2763261.html
Copyright © 2020-2023  润新知