Asp.net 在删除数据视图之前确认删除';s排
我有一个支持删除的GridView。我想添加一个弹出窗口,其中有一个问题,如“您确定要删除此行吗?” 我的代码:Asp.net 在删除数据视图之前确认删除';s排,asp.net,javascript,html,Asp.net,Javascript,Html,我有一个支持删除的GridView。我想添加一个弹出窗口,其中有一个问题,如“您确定要删除此行吗?” 我的代码: <asp:GridView id="GridAccounts" runat="server" AutoGenerateColumns="False" ShowFooter="True" DataKeyNames="ID" DataSourceID="AccountDataSource" onrowcommand="GridAccounts_R
<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>
这表现为:
<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;" />
若我在确认窗口中点击OK,回发会发生,但不会发生任何事情。如果我注释掉RowDataBound代码,那么delete工作正常。没有确认弹出窗口的代码:
<input type="image" src="Pictures/delete.jpg" alt="Delete" onclick="javascript:__doPostBack('ctl00$MainContent$GridPaymentMethod','Delete$0')" style="border-width:0px;" />
我做错了什么?我相信这就是你试图做的一个例子。它更干净,而且你不必对后面的代码发疯。我相信这就是你正在尝试做的一个例子。它更干净,您不必对代码发疯。在代码中,您必须将ButtonType=“Image”更改为ButtonType=“Link”-然后onclick=“…”将在不使用javascript的情况下呈现:\uuuuuu doPostBack(…)部分。在GridPaymentMethod_RowDataBound事件中,设置类似deleteButton.Text=“”(使用html实体而不是)
deleteButton.OnClientClick = string.Format("((!confirm('Are you sure you want to delete payment method {0}?'))?return false);", row.Name.Replace("'", @"\'"));
或者您可以将ImageButton与ComamndName=“delete”一起使用,并从ASP.NET AjaxToolkit套件中使用。在代码中,您必须将ButtonType=“Image”更改为ButtonType=“Link”-然后onclick=“…”将在不使用javascript的情况下呈现:\uuuuuudoPostback(…)部分。在GridPaymentMethod_RowDataBound事件中,设置类似deleteButton.Text=“”(使用html实体而不是)
或者您可以将ImageButton与ComamndName=“delete”一起使用,也可以从ASP.NET AjaxToolkit套件中使用。。CommandField并没有什么神奇之处——它只是添加了一个标准的链接按钮,将CommandName设置为要启动的操作。您只需将其替换为您自己的具有正确CommandName的LinkButton(例如CommandName=“Delete”将触发删除事件),这非常简单。CommandField并没有什么神奇之处——它只是添加了一个标准的链接按钮,将CommandName设置为要启动的操作。您只需将其替换为您自己的具有正确CommandName的LinkButton(例如CommandName=“Delete”将触发删除事件)。
deleteButton.OnClientClick = string.Format("((!confirm('Are you sure you want to delete payment method {0}?'))?return false);", row.Name.Replace("'", @"\'"));