但控件没有任何记录的时候,就什么也不显示,
但我仍然想让它把页头显示出来,怎么弄?

解决方案 »

  1.   

    在有内容的时候把页头的代码复制下来,然后放到            <EmptyDataTemplate>
                </EmptyDataTemplate>中,不知道能不能符合你的要求
      

  2.   

    /// <summary>
        /// 当DataSet为空时也显示GridView的表头
        /// </summary>
        /// <param name="gridView">所要绑定的GridView</param>
        /// <param name="ds">所要绑定的数据集</param>
        /// <returns></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;
       }
        }