请问dataGridView中如何删除行,dataGridView中的数据不是和数据库绑定的。
我知道选中一行按del键可以删除一行,但我现在需要在代码中删除行。

解决方案 »

  1.   

    参考:
    //删除
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string sqlstr = "delete from 表 where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
            sqlcon = new SqlConnection(strCon);
            sqlcom = new SqlCommand(sqlstr,sqlcon);
            sqlcon.Open();
            sqlcom.ExecuteNonQuery();
            sqlcon.Close();
            bind();
        }
      

  2.   

    ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[this.dataGridView1.CurrentRow.Index]);
      

  3.   

    如下的方法就可以了:this.dataGridView1.Rows.Remove(this.dataGridView1.CurrentRow);
      

  4.   

    其实二楼的也是需要的,他删除的是数据库中的,this.dataGridView1.Rows.Remove(this.dataGridView1.CurrentRow); 这只删除界面上的