当Girdview的数据源为空时,也显示表头

 protected  void  GridViewDatabind()
    {
        DataTable dt 
=  employer.GetPost();
        
if  (dt !=   null )
        {
            GridView1.ShowHeader 
=   true ;
            
if  (dt.Rows.Count  ==   0 )
            {

                dt.Rows.Add(dt.NewRow());
                GridView1.DataSource 
=  dt;
                GridView1.DataBind();
                GridView1.Rows[
0 ].Visible  =   false ;
                GridView1.Rows[
0 ].Cells.Clear();

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

        }

    }

你可能感兴趣的:(view)