更新时间:2023-12-04 11:35:22
请参阅下面的链接将获得您想要的内容: -
http://www.aspsnippets。 com / Articles / ASPNet-GridView --- Delete-Row-with-Confirmation.aspx [ ^ ]
refer below link will get what you want exactly:-
http://www.aspsnippets.com/Articles/ASPNet-GridView---Delete-Row-with-Confirmation.aspx[^]
它不会执行因为你没有添加任何命令字段
Its not going to execute coz u have not added any commandfields
<asp:commandfield showdeletebutton="True" />
所以你必须写一下图片按钮内部点击事件
试一下,让我知道..
so u have to write that inside click event of image button
try it and let me know..
<ItemTemplate>
<asp:ImageButton ID="imgbtnDelete" runat="server" ImageUrl="~/images/delete.png" CommandName="Cancel" />
</ItemTemplate>
当您使用 ImageButton
并且您有一个 CommandName
,所以你应该处理 GridView.RowCommand
事件 [ ^ ]。
为此声明 OnRowCommand
in GridView
标记。
As you are using ImageButton
and you have a CommandName
, so you should handle the GridView.RowCommand
Event[^].
For that declare OnRowCommand
in GridView
Markup.
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" Width="200" GridLines="None" OnRowCancelingEdit="GridView2_RowCancelingEdit" OnRowCommand="GridView2_RowCommand" >
然后在Code Beh上定义事件喜欢......
Then define the Event on Code Behind like...
protected void GridView2_RowCommand(Object sender, GridViewCommandEventArgs e)
{
// If multiple buttons are used in a GridView control, use the
// CommandName property to determine which button was clicked.
if(e.CommandName == "Cancel")
{
// Write your Delete Logic.
}
}