gpt4 book ai didi

asp.net - 在删除数据 View 的行之前确认删除

转载 作者:行者123 更新时间:2023-11-28 16:40:16 25 4
gpt4 key购买 nike

我有一个支持删除的GridView。我想添加一个弹出窗口,其中包含“您确定要删除此行吗?”之类的问题。

我的代码:

<asp:GridView id="GridAccounts" runat="server" AutoGenerateColumns="False" 
ShowFooter="True" DataKeyNames="ID"
DataSourceID="AccountDataSource" onrowcommand="GridAccounts_RowCommand">
<SelectedRowStyle BackColor="Lime" />
<Columns>
<asp:CommandField ButtonType="Image" ShowDeleteButton="True" DeleteImageUrl="~/Pictures/delete.jpg" />
<asp:TemplateField HeaderText="ID" InsertVisible="False" SortExpression="ID">
<EditItemTemplate>
<asp:Label ID="LabelAccountIDUpdate" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="ButtonAccountIDInsert" runat="server" CommandName="Insert" Text="Insert" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="LabelAccountID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

隐藏代码:

protected void GridPaymentMethod_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton deleteButton = (ImageButton)e.Row.Cells[0].Controls[0];
MyMoney.PaymentMethodRow row = (MyMoney.PaymentMethodRow)((System.Data.DataRowView)e.Row.DataItem).Row;
deleteButton.OnClientClick = string.Format("return confirm('Are you sure you want to delete payment method {0}?');", row.Name.Replace("'", @"\'"));
}
}

这呈现为:

<input type="image" src="Pictures/delete.jpg" alt="Delete" onclick="return confirm('Are you sure you want to delete payment method Gotovina?');javascript:__doPostBack('ctl00$MainContent$GridPaymentMethod','Delete$0')" style="border-width:0px;" />

如果我在确认窗口上单击“确定”,则会发生回发,但什么也没有发生。如果我注释掉 RowDataBound 代码,则删除工作正常。没有弹出确认的代码:

<input type="image" src="Pictures/delete.jpg" alt="Delete" onclick="javascript:__doPostBack('ctl00$MainContent$GridPaymentMethod','Delete$0')" style="border-width:0px;" />

我做错了什么?

最佳答案

我相信this是您正在尝试做的事情的一个例子。它更干净,您不必为后面的代码而烦恼。

关于asp.net - 在删除数据 View 的行之前确认删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1234713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com