我使用的是ASP C# VS 2015。我设法用来自MySQL的数据生成了一个网格视图。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>
发布于 2017-11-16 13:12:30
尝尝这个
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; };";
}
}
}
}
https://stackoverflow.com/questions/47330218
复制相似问题