zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    springboot——helloworld探究
    springboot——主程序类,主入口类
    android&nbsp;setClickable&nbsp;不起作用&nbsp;没…
    JAVA&nbsp;线程&nbsp;开启线程&nbsp;一个类里只开…
    eclipse 自动提示不出来
    android&nbsp;禁止回退&nbsp;不许回退
    一插上USB外设以后&nbsp;直接跳到相应的…
    Android&nbsp;UI设计中的特效&nbsp;界面左右…
    SysUtils.FmtStr、SysUtils.Format 格式化输出和ShowMessageFmt用法
    嘉猪昨天流鼻血了
  • 原文地址:https://www.cnblogs.com/qianxingdewoniu/p/2763261.html
Copyright © 2011-2022 走看看