If you just delete the rows in the GridView, the records in the database are not deleted
Item Times |
Work No. |
name |
|
1 |
10022936 |
Gracy.ma |
Delete |
2 |
10017300 |
Eric.mak |
Delete |
protected void Button1_Click (object sender, EventArgs e)
{
int rowCount = 1;
DataTable DT = new DataTable ();
DataRow DR;
Dt. Columns.Add ("Order_no");
Dt. Columns.Add ("Emp_no");
Dt. Columns.Add ("NAME");
for (int iRow = 0; IRow < GridView1.Rows.Count; irow++)
{
DR = DT. NewRow ();
Dr[0] = RowCount;
DR[1] = Gridview1.rows[irow]. CELLS[1]. Text.trim ();
DR[2] = Gridview1.rows[irow]. CELLS[2]. Text.trim ();
Dt. Rows.Add (DR);
rowcount++;
}
DR = DT. NewRow ();
Dr[0] = RowCount;
DR[1] = this. TextBox1.Text.Trim ();
DR[2] = this. TextBox2.Text.Trim ();
Dt. Rows.Add (DR);
Gridview1.datasource = DT;
Gridview1.databind ();
session["DataTable"] = DT;
}
protected void Gridview1_rowdeleting (object sender, Gridviewdeleteeventargs e)
{
DataTable dt= (DataTable) session["DataTable"];
Dt. Rows.removeat (E.rowindex);
Gridview1.datasource = DT;
Gridview1.databind ();
}
Article from http://mgracy.blog.163.com/blog/static/5764989820114811369947/
GridView rowdeleting dynamic add row, delete row record does not delete record in database