如果只需删除GridView中的行, 并不删除数据库中的记录
项次 | 工号 | 姓名 | |
---|---|---|---|
1 | 10022936 | gracy.ma | 删除 |
2 | 10017300 | eric.mak | 删除 |
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();
}
文章来自于http://mgracy.blog.163.com/blog/static/5764989820114811369947/