在数据源没有数据的时候:
         DataSet ds = new DataSet();
            ds =...
            DataTable dt = ds.Tables[0];
            if (dt.Rows.Count <= 0)
            {
                DataRow dr = dt.NewRow();
                dt.Rows.Add(dr);
            }
            this.GridView1.DataSource = dt;
            GridView1.DataBind();
     
        在点击按钮新增一行的时候
       DataSet ds = new DataSet();
         ds = ....
        DataTable dt = ds.Tables[0];
        if (dt.Rows.Count >= 0)
        {
            DataRow dr = dt.NewRow();
            dt.Rows.Add(dr);
        }
        this.GridView1.DataSource = dt;
        GridView1.DataBind();

相关文章: