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..
I am getting index out of range error message.. please help
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Iftikar HussainRank #423 · 5.9K reputationPosted Jul 6, 2013, 8:41 AM EDT
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