我在一个button事件里这样写   DataTable dt = ds.Tables[0];
        DataRow dr = dt.NewRow();
        dt.Rows.Add(dr);
            GridView1.DataSource = ds;
        GridView1.DataBind();
 dsAllNodes.Tables[0];是从数据库那里读出来的,主键是int型。 GridView1那里显示一条空行了,
用if(GridView1.Rows[index].Cells[0].Text=="")和if(GridView1.Rows[index].Cells[0].Text==null)都判断不出来,究竟那是什么值呢?我新建了个label,用label。Text=GridView1.Rows[index].Cells[0].Text显示为什么值都没有。

解决方案 »

  1.   

    兄弟:
    GridView添加新行一般在Footer中进行:
    1.先设置GridView的ShowFooter属性为true;
    2.将GridView各列转换成模板列;
    3.进入GridView的"编辑模板"画面,
      在FooterTemplate处添加相应的TextBox或Button
    4.编写代码,保存TextBox框中的内容到数据表!!
      

  2.   

    DataRow dr = dt.NewRow(); 
    dr[""] =  DBNull.Value;   
    dt.Rows.Add(dr);
    或采用Footer
    参考
    http://www.cnblogs.com/liangwei389/archive/2008/12/18/1357751.html
      

  3.   

    问题描述有点问题哦!
    只能猜了。对dt添加新行后并没有使用dt做为GridView的数据源,然而ds依然没有改变值!