Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP C#Gridview确认删除并用文本消息提示用户_C#_Asp.net_.net_Gridview - Fatal编程技术网

ASP C#Gridview确认删除并用文本消息提示用户

ASP C#Gridview确认删除并用文本消息提示用户,c#,asp.net,.net,gridview,C#,Asp.net,.net,Gridview,我使用的是ASP C#VS 2015。我设法用MySQL中的数据生成了一个gridview。update和delete命令显示为链接,我设法将它们正确地连接到事件 现在我想添加一个功能,在删除前添加确认信息,并添加一条消息(文本框)以说明删除原因 如何在.NET中实现这一点 我精通PHP和jQuery,但仍在学习.NET中的曲线。 提前谢谢 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerate

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

现在我想添加一个功能,在删除前添加确认信息,并添加一条消息(文本框)以说明删除原因

如何在.NET中实现这一点

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

<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>

试试这个

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; };";
            }
        }
    }
}
受保护的void OnRowDataBound(对象发送方,GridViewRowEventArgs e)
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
字符串项=e.Row.Cells[0]。文本;
foreach(e.Row.Cells[2].Controls.OfType()中的按钮)
{
如果(button.CommandName==“删除”)
{
button.Attributes[“onclick”]=“if(!confirm('是否要删除“+项+”?')){return false;};”;
}
}
}
}