首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用文本消息对删除和提示用户进行ASP C# Gridview确认

使用文本消息对删除和提示用户进行ASP C# Gridview确认
EN

Stack Overflow用户
提问于 2017-11-16 12:55:16
回答 1查看 566关注 0票数 0

我使用的是ASP C# VS 2015。我设法用来自MySQL的数据生成了一个网格视图。update和delete命令显示为链接,我设法将它们正确地连接到事件中。

现在,我想添加一个功能,以添加确认前删除加上消息(文本框)的原因删除?

我如何在.NET中做到这一点?

我精通PHP和jQuery,但仍在.NET中学习曲线,谢谢。

代码语言:javascript
运行
复制
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="id"
            OnRowDataBound="OnRowDataBound" OnRowEditing="OnRowEditing" OnRowCancelingEdit="OnRowCancelingEdit"
            OnRowUpdating="OnRowUpdating" EmptyDataText="No records has been added." OnRowDeleting="OnRowDeleting" OnRowDeleted="OnRowDeleted">
   <Columns>
       <asp:TemplateField HeaderText="Id" ItemStyle-Width="20">
           <ItemTemplate>
               <asp:Label ID="lblId" runat="server" Text='<%# Eval("id") %>'></asp:Label>
           </ItemTemplate>
           <ItemStyle Width="20px"></ItemStyle>
       </asp:TemplateField>
       <asp:TemplateField HeaderText="Email">
           <ItemTemplate>
               <asp:Label ID="lblEmail" runat="server" Text='<%# Eval("email") %>'></asp:Label>
           </ItemTemplate>
       </asp:TemplateField>
       <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" DeleteText="Reject" headertext="Controls"></asp:CommandField>
   </Columns>
</asp:GridView>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-16 13:12:30

尝尝这个

代码语言:javascript
运行
复制
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        string item = e.Row.Cells[0].Text;
        foreach (Button button in e.Row.Cells[2].Controls.OfType<Button>())
        {
            if (button.CommandName == "Delete")
            {
                button.Attributes["onclick"] = "if(!confirm('Do you want to delete " + item + "?')){ return false; };";
            }
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47330218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档