嘿,伙计们,我正在尝试删除项目模板按钮上的一行,但是当从我的GridView.DeleteRow方法中调用OnRowCommand方法时,我得到了错误:
The GridView 'MyGridView' fired event RowDeleting which wasn't handled据我所知,只有当您将RowDeleting设置为Delete时才会调用CommandName?
下面是我的GridView和OnRowCommand的示例
Gridview
<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上学习这,但到目前为止还没有取得任何成功。请帮帮忙。
发布于 2014-06-13 18:40:01
在这里您遗漏了一件事--调用Gv_SelectedLineItems.DeleteRow(index)有意义地期待RowDeleting函数。
混淆是因为您已经在按钮回调中,而delete命令有时也是这样。
当您在DeleteRow上使用GridView时,它要求您有此事件--希望您能够处理可能需要在其中预删除的任何内容。
您的按钮单击- "RemoveRow"是无关的删除,它只是一个按钮点击。
编辑:
您需要创建一个RowDeleting事件处理程序。在你的代码背后;
protected void Gv_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
}在GridView的顶部,您需要添加事件处理程序:
<asp:GridView ID="MyGridView" runat="server" OnRowCommand="Gv_RowCommand" OnRowDeleting="Gv_RowDeleting">https://stackoverflow.com/questions/24211424
复制相似问题