protected void grdCustomer_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EDT") { int rowIndex = Convert.ToInt32(e.CommandArgument); grdCustomer.SelectedIndex = rowIndex; hdnCustomerID.Value = ((HiddenField)grdCustomer.Rows[rowIndex].FindControl("hdnCustomerID")).Value; txtFirstName.Text = ((LinkButton)grdCustomer.Rows[rowIndex].FindControl("lnkFirstName")).Text; txtLastName.Text = ((HyperLink)grdCustomer.Rows[rowIndex].FindControl("hypLastName")).Text; txtBirthDate.Text = ((Label)grdCustomer.Rows[rowIndex].FindControl("lblBirthDate")).Text; txtEmail.Text = ((Label)grdCustomer.Rows[rowIndex].FindControl("lblEmail")).Text; txtAddress.Text = ((Label)grdCustomer.Rows[rowIndex].FindControl("lblAddress")).Text; } else if (e.CommandName == "DLT") { int rowIndex = Convert.ToInt32(e.CommandArgument); hdnCustomerID.Value = ((HiddenField)grdCustomer.Rows[rowIndex].FindControl("hdnCustomerID")).Value; CustomerBAL obj = new CustomerBAL(); int retVal = obj.DeleteCustomer(Convert.ToInt64(hdnCustomerID.Value)); obj = null; if (retVal > 0) { BindGrid(); ClearControls(); Page.ClientScript.RegisterStartupScript(this.GetType(), "Deleted", "<script>alert('Deleted successfully.');</script>"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Deleted", "<script>alert('Error while deleting.');</script>"); } } }
public IActionResult DeleteCustomer(int id) { try { CustomerBAL.DeleteCustomer(id); return(Ok()); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to delete Customer")); } }