添加一个JavaScript确认提示删除命令按钮在ASP.NET网格视图? [英] Adding a JavaScript confirmation prompt to a delete command button in an ASP.NET grid view?

查看:135
本文介绍了添加一个JavaScript确认提示删除命令按钮在ASP.NET网格视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一个ASP.NET网格视图:

So I have an ASP.NET grid view:

<asp:GridView ID="gvReferences" runat="server" AutoGenerateColumns="False" ShowHeader="False"
    OnRowEditing="gvReferences_RowEditing" 
    OnRowDeleting="gvReferences_RowDeleting" onrowcreated="gvReferences_RowCreated">
    <Columns>
        <asp:TemplateField ItemStyle-Width="400px">
            <ItemTemplate>
                <asp:Label ID="lblId" Visible="false" runat="server" Text='<%# Eval("Id") %>' />
                <asp:Label ID="lblAssociatedSpecies" runat="server" Text='<%# Eval("Text") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="lblKind" runat="server" Text='<%# Eval("Kind") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:CommandField ButtonType="Button" DeleteText="delete" ShowDeleteButton="True"
            ShowCancelButton="False" EditText="edit" ShowEditButton="True">
            <ControlStyle Width="60px" />
        </asp:CommandField>
    </Columns>
</asp:GridView>

我想一些JavaScript附加到<大骨节病>删除命令按钮被删除的行之前,要求确认。

I'd like to attach some JavaScript to the Delete command button to ask for confirmation before a row is deleted.

任何想法?

推荐答案

您总是可以使用一个TemplateField,而不是CommandField中。

You could always use a TemplateField rather than the CommandField.

<asp:TemplateField>
  <ItemTemplate>
    <asp:Button name="btnDelete" commandName="Delete" OnClientClick="return confirm('Delete 
this Item');" Text="Delete" runat="server" />
    <asp:Button name="btnEdit" commandName="Edit" Text="Edit" runat="server" />
  </ItemTemplate>
</asp:TemplateField>

这篇关于添加一个JavaScript确认提示删除命令按钮在ASP.NET网格视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆