码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2015-01-17 16:25:12      阅读:229      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!