首页 > 数据库技术 > 详细

GridView RowDeleting 动态添加行,删除行记录 不删除数据库中记录

时间:2015-01-17 16:22:01      阅读:298      评论:0      收藏:0      [点我收藏+]

如果只需删除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/

GridView RowDeleting 动态添加行,删除行记录 不删除数据库中记录

原文:http://www.cnblogs.com/hqhouse/p/4230517.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!