【发布时间】:2014-06-13 18:08:29
【问题描述】:
大家好,我正在尝试在单击 itemtemplate 按钮时删除一行,但是在我的 OnRowCommand 方法中调用 GridView.DeleteRow 方法时,我收到了错误:
The GridView 'MyGridView' fired event RowDeleting which wasn't handled
据我所知,RowDeleting 只有在您将 CommandName 设置为 Delete 时才会被调用?
这是我的GridView 和OnRowCommand 的示例:
网格视图
<asp:GridView ID="MyGridView" runat="server" OnRowCommand="Gv_RowCommand">
<Columns>
.
.
.
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImgBtn" runat="server" CommandName="RemoveRow" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" ImageUrl="img.png" ToolTip="Remove" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
OnRowCommand 背后的代码
protected void Gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "RemoveRow")
{
int index = Convert.ToInt32(e.CommandArgument);
//THROWS EXCEPTION
Gv_SelectedLineItems.DeleteRow(index);
}
}
我一直在 msdn 上关注 this 示例,但到目前为止还没有成功。请帮忙。
【问题讨论】:
-
您是否考虑过仅使用空处理程序处理事件?
-
那么创建没有正文的“RowDeleting”处理程序?这是最佳做法吗?