子风.NET 进阶中......

路途多艱,唯勤是岸

 

当没有数据时,girdview不显示任何东西,但是需要显示列名.

1 自己写个dt里面新建一个datarow,函数如下:
///   <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;   
        }
   
  }

2:girdview里面有个EmpyDataTempLate 这个模板列就是当你的数据源为空时显示的,你自己可以在里面拉一个table 写上你的表头.

3: 用其他的控件:如repeater.

posted on 2007-06-19 13:40  子风  阅读(530)  评论(0编辑  收藏  举报

导航