zoukankan      html  css  js  c++  java
  • GridView 的EmptyDataText 及 EmptyDataTemplate

    当GridView绑定的数据源为Null或查询绑定的DataSet等为空时
    GridView显示没有数据的提示

    有如下几种方式

    一是用GridView的EmptyDataText
    -------------------------------
    <asp:GridView ID="gv_Info" runat="server" CssClass="GridView"
       EditRowStyle-HorizontalAlign="center" AutoGenerateColumns="True"
       AllowPaging="True" PageSize="4"  Width="100%" RowStyle-HorizontalAlign="center"
       AllowSorting="True" OnSorted="gv_Info_Sorted" OnSorting="gv_Info_Sorting"
       EmptyDataRowStyle-CssClass="GridViewNoData"
       EmptyDataText="暂没有数据"
       EmptyDataRowStyle-HorizontalAlign="center"
       EmptyDataRowStyle-Font-Bold="true"
    >  

    后台可用如下方式进行修改其显示

    this.gv_Info.EmptyDataText = "No No No Data";

               
    二是用GridView的EmptyDataTemplate
    -------------------------------
    <EmptyDataTemplate>
       <table width="100%" cellpadding="0" cellspacing="0" class="">
             <tr align="center">
                  <td style="height: 40px;" runat="server"  id="td_EmptyData">
                         <b>请点选[统计查看]按钮 或者 统计暂没有数据</b></td>
                  </tr>
        </table>
        <asp:Label runat="server" ID="lbl_EmptyData" Text="No Data"></asp:Label>
    </EmptyDataTemplate>

    后台可用如下方式进行修改其显示

    Table gvTable = ((Table)this.gv_Info.Controls[0]);
    Label tmpLabel = (Label)(gvTable.Rows[0].FindControl("lbl_EmptyData"));
    tmpLabel.Text = "No No No Data";

    三是当然也可以在GridView没有显示时 显示预先设定好的Table

    附:
    上述两种方式一起使用时 显示时将以第二种方式为主

    再有 清空GridView显示
    //this.gv_Info.EmptyDataText = "No Data";
    this.gv_Info.DataSource = null;
    this.gv_Info.DataBind();

  • 相关阅读:
    ES6的reduce( )方法 可以数组求和、数组去重、二维数组转一维数组、计算数组中每个元素出现的次数
    防止/禁止页面后退
    CSS预处理器SASS将迁移到Dart Sass
    FormData 对象的使用
    javascript中编码与解码的decodeURI()、decodeURIComponent()区别
    Chrome谷歌浏览器调试技巧小结
    javaweb:tomcat&servlet
    java:Druil连接池
    java:c3p0连接池的使用
    java:JDBC的使用方式
  • 原文地址:https://www.cnblogs.com/freeliver54/p/1212692.html
Copyright © 2011-2022 走看看