GridView rowdeleting dynamic add row, delete row record does not delete record in database

Source: Internet
Author: User
Tags rowcount

If you just delete the rows in the GridView, the records in the database are not deleted

Item Times Work No. name  
1 10022936 Gracy.ma Delete
2 10017300 Eric.mak Delete

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 ();
}

Article from http://mgracy.blog.163.com/blog/static/5764989820114811369947/

GridView rowdeleting dynamic add row, delete row record does not delete record in database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.