protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("EmpId", typeof(string)));
dt.Columns.Add(new DataColumn("EmpName", typeof(string)));
dt.Columns.Add(new DataColumn("DeptName", typeof(string)));
dt.Columns.Add(new DataColumn("EmpAddress", typeof(string)));
dt.Columns.Add(new DataColumn("EmpSalary", typeof(string)));
string Id = string.Empty;
string Name = string.Empty;
string DeptName = string.Empty;
string EmpAddress = string.Empty;
string EmpSalary = string.Empty;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = (GridViewRow)GridView1.Rows[i];
if (i != e.RowIndex)
{
Id = row.Cells[1].Text;
Name = row.Cells[2].Text;
DeptName = row.Cells[3].Text;
EmpAddress = row.Cells[4].Text;
EmpSalary = row.Cells[5].Text;
DataRow dr = dt.NewRow();
dr["EmpId"] = Id;
dr["EmpName"] = Name;
dr["DeptName"] = DeptName;
dr["EmpAddress"] = EmpAddress;
dr["EmpSalary"] = EmpSalary;
dt.Rows.Add(dr);
}
}
GridView1.EditIndex = -1;
GridView1.DataBind();
GridView1.DataSource = dt;
}
This code is deleting row but after adding new row the deleted row appears once again could any one help me
Thanks in Advance

Ronika JencyRank #770 · 3K reputationPosted Nov 25, 2019, 9:12 PM EST
Hi,
Finally the DataTable is saved back to the ViewState and the GridView is again populated.
Below code is delete from gridview datatable.Below is code delete from table,
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 25, 2019, 9:39 PM EST
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 25, 2019, 10:46 PM EST
Syed Taha21 reputationPosted Nov 25, 2019, 10:46 PM EST
Syed Taha21 reputationPosted Nov 25, 2019, 10:52 PM EST
Ronika JencyRank #770 · 3K reputationPosted Nov 25, 2019, 10:57 PM EST
Syed Taha21 reputationPosted Nov 25, 2019, 11:01 PM EST
Ronika JencyRank #770 · 3K reputationPosted Nov 25, 2019, 11:17 PM EST
Syed Taha21 reputationPosted Nov 25, 2019, 11:24 PM EST
Ronika JencyRank #770 · 3K reputationPosted Nov 25, 2019, 11:44 PM EST
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 26, 2019, 1:34 AM EST