基本上,当我们单击 GridView 中的删除(链接按钮)时,我正在尝试创建一个 sweetalert 删除操作。当我在 Sweetalert 上单击删除选项时,记录并没有被删除。
这是我的 .aspx 代码
<asp:LinkButton OnClientClick="return deletealert(this);" ID="LinkButton2" CommandArgument='<%#Eval("EmployeeId")%>' runat="server" CommandName="CmdDelete" Text="Delete" />
这是我的解雇方法背后的代码
protected void `gvEmployeeDetails_RowCommand`(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "CmdEdit")
{
Response.Redirect("EmployeeRegistration.aspx?ItemId=" + e.CommandArgument);
}
else if (e.CommandName == "CmdDelete")
{
int EmployeeId = Convert.ToInt32(e.CommandArgument);
obj.Remove(EmployeeId);
GetData();
}
}
这是 JavaScript 代码
function deletealert(ctl) {
// STORE HREF ATTRIBUTE OF LINK CTL (THIS) BUTTON
var defaultAction = $(ctl).prop("href");
// CANCEL DEFAULT LINK BEHAVIOUR
event.preventDefault();
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
}, function (isConfirm) {
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
// RESUME THE DEFAULT LINK ACTION
eval(defaultAction);
return true;
} else {
swal("Cancelled", "Your imaginary file is safe ", "error");
return false;
}
});