protected void grdPersonsDetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
cmd.Connection = con;
int PersonId = int.Parse(Request.QueryString["Id"].ToString());
if (e.CommandName == "EditContactPerson")
{
btnUpdate.Visible = true;
btnSave.Visible = false;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT ContactPersonId,Name,Address,Place,Phone,ImagePath FROM tbl_ContactPerson WHERE ContactPersonId=@ContactPersonId";
cmd.Parameters.AddWithValue("@ContactPersonId", PersonId);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
txtName.Text = dr["Name"].ToString();
txtAddress.Text = dr["Address"].ToString();
txtPlace.Text = dr["Place"].ToString();
txtPhone.Text = dr["Phone"].ToString();
hdfContactPersonId.Value = dr["ContactPersonId"].ToString();
}
con.Close();
}
if (e.CommandName == "Delete")
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = "DELETE FROM tbl_ContactPerson WHERE ContactPersonId=@ContactPersonId";
cmd.Parameters.AddWithValue("@ContactPersonId", PersonId);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
FillData();
}
}
Update and Delete function onRowCommand event