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/

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。