zoukankan      html  css  js  c++  java
  • GridView控件在没有数据时显示表头和没有数据

    一、EmptyDataTemplate,在这个模版中设置

    <EmptyDataTemplate>
        
    <table>
           
    <tr>
              
    <td></td>
              
    <td></td>
              
    <td></td>
              
           
    </tr>
           
    <tr>
              
    <td>--没有记录--</td>
           
    </tr>
        
    </table>
    </EmptyDataTemplate>
    二、数据源为datatable 
    DataTable dt = userbll.GetList("").Tables[0];

            
    if (dt.Rows.Count == 0)
            
    {
                dt.Rows.Add(dt.NewRow());
                GridView1.DataSource 
    = dt;
                GridView1.DataBind();

                
    int columnCount = dt.Columns.Count;
                GridView1.Rows[
    0].Cells.Clear();
                GridView1.Rows[
    0].Cells.Add(new TableCell());
                GridView1.Rows[
    0].Cells[0].ColumnSpan = columnCount;
                GridView1.Rows[
    0].Cells[0].Text = "---没有记录---";
                GridView1.Rows[
    0].Cells[0].Style.Add("text-align""center");
            }

            
    else
            
    {
                GridView1.DataSource 
    = dt;
                GridView1.DataBind();
            }

        }
  • 相关阅读:
    Redis之String
    代码质量管理工具——SonarQube
    XML文件(2)--使用DOM4J示例
    XML文件(1)--使用DOM示例
    Maven之构件
    使用JS,获取URL中指定参数的值
    jQuery导入Eclipse后报错解决方法
    关于MySQL存储过程中遇到的一个错误
    学习MySQL之数据类型(四)
    jmeter直连数据库【转】
  • 原文地址:https://www.cnblogs.com/puke/p/773108.html
Copyright © 2011-2022 走看看