所以我现在遇到麻烦,在弹出模态后无法让我的程序删除一行。模态有效,但是当我单击“确定”按钮时,我要删除的行仍然存在并且未被删除。有关如何解决此问题的任何想法?
我试图切换一些代码,以查看是否有任何更改,但其他任何方法都无效。
删除模态
<!--for Delete:-->
<div id="DeleteModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Delete User Account</h4>
</div>
<div class="modal-body">
<asp:Label ID="lblDeleteID" runat="server" Text="" Visible="false"></asp:Label>
Are you sure you want to delete this record?
</div>
<div class="modal-footer">
<asp:Button ID="btnExecuteDelete" class="btn btn-default" runat="server" Text="OK" OnClick="btnExecuteDelete_Click"/>
<asp:Button ID="btnCancelDelete" class="btn btn-default" runat="server" Text="Cancel" data-dismiss="modal"/>
</div>
</div>
</div>
</div>
GRIDVIEW
<asp:GridView ID="gvGuest" runat="server" AutoGenerateColumns="False"
OnPageIndexChanging="PageIndexChanging" AllowPaging="true" PageSize="5"
DataKeyNames="GuestID">
<Columns>
<asp:TemplateField HeaderText="Guest ID">
<ItemTemplate>
<asp:Label ID="lblGuestID" runat="server" Text='<%#Eval("GuestID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First Name">
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("FirstName")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<asp:Label ID="lblLastName" runat="server" Text='<%#Eval("LastName")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone">
<ItemTemplate>
<asp:Label ID="lblPhone" runat="server" Text='<%#Eval("Phone")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="">
<ItemTemplate>
<asp:LinkButton ID="btnUpdate" runat="server" ForeColor="Blue" OnClick="btnUpdate_Click">Edit</asp:LinkButton>
<asp:LinkButton ID="btnDelete" runat="server" ForeColor="Red" OnClick="btnDelete_Click">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
删除CS代码
protected void btnExecuteDelete_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myPrompt", "alert('Successfully Deleted Record!');", true);
}
protected void btnDelete_Click(object sender, EventArgs e)
{
clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
pk = ((Label)clickedRow.FindControl("lblGuestID")).Text;
lblDeleteID.Text = pk.ToString();
objBEL.GuestID = GuestID;
objBLL.DeleteGuest(objBEL);
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "DeleteModal", "$('#DeleteModal').modal();", true);
readGrid();
objBEL = null;
objBLL = null;
}
BLL
public void DeleteGuest(GuestBEL objBEL)
{
GuestDAL objDAL = new GuestDAL();
objDAL.DeleteGuest(objBEL);
}
DAL
public void DeleteGuest(GuestBEL objBEL)
{
SqlCommand cmd = new SqlCommand("GuestDelete", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@GuestID", objBEL.GuestID);
con.Open();
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
}
存储过程
CREATE PROCEDURE [dbo].[GuestDelete]
@GuestID int
AS
BEGIN
DELETE FROM Guest
WHERE GuestID=@GuestID
END
因此对于模态,当我单击删除按钮时,模态会弹出,询问用户是否确定是否要删除记录,单击确定后,它将显示一条消息,说明记录已成功已删除。因此,当我运行代码时,模态没有问题,我遇到的唯一问题是它没有删除行。如果您可以帮助我解决问题,我将不胜感激:)