当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();
            }

        }

    }
posted @ 2009-09-15 21:07  ForFreeDom  阅读(222)  评论(0编辑  收藏  举报