zoukankan      html  css  js  c++  java
  • 当DataSet为空时也显示GridView的表头

    /**//// <summary>
    /// 当DataSet为空时也显示GridView的表头
    /// </summary>
    /// <param name="gridView">所要绑定的GridView</param>
    /// <param name="ds">所要绑定的数据集</param>
    /// <returns>void </returns>

    public void BindNoRecords(GridView gridView, DataSet ds)
    {
         
    if (ds.Tables[0].Rows.Count == 0)
         
    {
              ds.Tables[
    0].Rows.Add(ds.Tables[0].NewRow());
              gridView.DataSource 
    = ds;
              gridView.DataBind();
             
    int columnCount = gridView.Rows[0].Cells.Count;
              gridView.Rows[
    0].Cells.Clear();
              gridView.Rows[
    0].Cells.Add(new TableCell());
              gridView.Rows[
    0].Cells[0].ColumnSpan = columnCount;
              gridView.Rows[
    0].Cells[0].Text = "没有数据";
              gridView.RowStyle.HorizontalAlign 
    = System.Web.UI.WebControls.HorizontalAlign.Center;
         }

    }
        

    注:其他数据源 如 dataview datatable也类似的写法
    if (dv.Count == 0)
            
    {
                dv.Table.Rows.Add(dv.Table.NewRow());

                
    this.Gv_Storage.DataSource = dv;
                
    this.Gv_Storage.DataBind();
                
    int count =this.Gv_Storage.Rows[0].Cells.Count;
                Gv_Storage.Rows[
    0].Cells.Clear();
                Gv_Storage.Rows[
    0].Cells.Add(new TableCell());
                Gv_Storage.Rows[
    0].Cells[0].ColumnSpan = count;
                Gv_Storage.Rows[
    0].Cells[0].Text = "没有记录";
                Gv_Storage.RowStyle.HorizontalAlign 
    = System.Web.UI.WebControls.HorizontalAlign.Center;
            }

            
    else
            
    {
                
    this.Gv_Storage.DataSource = dv;
                
    this.Gv_Storage.DataBind();
            }

     

    我的淘宝店:http://hamby.taobao.com
  • 相关阅读:
    python 的基础 学习 第六天 基础数据类型的操作方法 字典
    python 的基础 学习 第五天 基础数据类型的操作方法
    python 的基础 学习 第四天 基础数据类型
    ASP.NET MVC 入门8、ModelState与数据验证
    ASP.NET MVC 入门7、Hellper与数据的提交与绑定
    ASP.NET MVC 入门6、TempData
    ASP.NET MVC 入门5、View与ViewData
    ASP.NET MVC 入门4、Controller与Action
    ASP.NET MVC 入门3、Routing
    ASP.NET MVC 入门2、项目的目录结构与核心的DLL
  • 原文地址:https://www.cnblogs.com/hambywu/p/1172290.html
Copyright © 2011-2022 走看看