protected void dgShow_DeleteCommand(object source, DataGridCommandEventArgs e)
{
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
int enpid = (int)dgShow.DataKeys[(int)e.Item.ItemIndex];
cmd.CommandText = "Delete * from EmpTable where EmpId=" + enpid;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
dgShow.EditItemIndex = -1;
Show();
}
this was block of code..
Loading
Iftikar HussainPosted Jul 6, 2013, 12:41 PM
I have modified your code. Please check
protected void dgShow_DeleteCommand(object source, DataGridCommandEventArgs e)
{
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
int enpid = (int)e.Item.Cells[1]; // you need provide the cell number where the empid is displayed in the grid
cmd.CommandText = "Delete * from EmpTable where EmpId=" + enpid;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
dgShow.EditItemIndex = -1;
Show();
}
Regards,
Iftikar