GridView RowDeleting 动态添加行,删除行记录 不删除数据库中记录
如果只需刪除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/
轉載于:https://www.cnblogs.com/hqhouse/p/4230517.html
總結
以上是生活随笔為你收集整理的GridView RowDeleting 动态添加行,删除行记录 不删除数据库中记录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【转】Linux面试题集锦
- 下一篇: Tomcat数据源总结