在网上只查到了在GridView的ButtonField的LinkButton中添加删除确认对话框,如下: <asp:ButtonField CommandName="Delete" HeaderText="删除" ShowHeader="True" Text="删除" /> --这是在GridView源中删除按钮的代码.删除按钮在Cells[8].
再在 protected void GV_repair_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[8].Attributes.Add("onclick", "return confirm('确定删除?')");
}
但是我用的是CommandField,有编辑和删除两个按钮:
<asp:CommandField HeaderText="编辑" ShowDeleteButton="True" ShowEditButton="True" ShowHeader="True" > </asp:CommandField>
如何实现在点击CommandField中的删除按钮时出现确认对话框?
请高手指导!
再在 protected void GV_repair_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[8].Attributes.Add("onclick", "return confirm('确定删除?')");
}
但是我用的是CommandField,有编辑和删除两个按钮:
<asp:CommandField HeaderText="编辑" ShowDeleteButton="True" ShowEditButton="True" ShowHeader="True" > </asp:CommandField>
如何实现在点击CommandField中的删除按钮时出现确认对话框?
请高手指导!
看看我的:
<Columns>
<asp:CommandField
ShowEditButton="True" UpdateText="Save">
<ItemStyle Wrap="False" />
</asp:CommandField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick='return confirm("Are you sure you want to delete this entry?");'
Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
完后退出该字段设计器,切换到源码视图你会发现该列已由原来的:<asp:CommandField ShowDeleteButton="True" />
变为了:
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" Text="删除"></asp:LinkButton>
</ItemTemplate>
然后就可以针对Linkbutton1写事件了。