GridView'OrdersGridView'引发了未处理的事件RowDeleting [英] The GridView 'OrdersGridView' fired event RowDeleting which wasn't handled

查看:64
本文介绍了GridView'OrdersGridView'引发了未处理的事件RowDeleting的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一次又一次地遇到此错误.

I’m getting this error over and over again.

将数据加载到GridView中是可行的,但是当我想删除一行时,我会收到该错误.

Loading the data into the GridView works, but when I want to delete a row I'm getting that error.

<asp:GridView ID="OrdersGridView" runat="server" AutoGenerateColumns="False" onrowdeleted="OrdersGridView_RowDeleted">
    <Columns>
        <asp:TemplateField HeaderText="Product Name">
            <ItemTemplate>
                <asp:HiddenField runat="server" ID="HiddenField1" Value='<%#Eval("oid")%>'></asp:HiddenField>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="titel" HeaderText="Name" />
        <asp:BoundField DataField="oid" HeaderText="Itemno" />
        <asp:BoundField DataField="prijs" HeaderText="Price" />
        <asp:CommandField ButtonType="Link" CausesValidation="false" HeaderText="Update" ShowDeleteButton="True" />
        <asp:BoundField DataField="prijs" HeaderText="Subtotal" />
    </Columns>
</asp:GridView>

C#代码隐藏-我并没有真正从数据库中删除该行,但这是一个测试:

C# codebehind - I'm not really deleting the row from the database but it's a test:

protected void OrdersGridView_RowDeleted(object sender, System.Web.UI.WebControls.GridViewDeletedEventArgs e)
{
    if (e.Exception != null)
    {
        lblStatus.Text = e.Exception.ToString();
    }
    else 
    {
        string sValue = ((HiddenField)OrdersGridView.SelectedRow.Cells[1].FindControl("HiddenField1")).Value;
        lblStatus.Text = sValue;
    }
}

但是,单击后,我得到一个大黄页,并显示下一个错误:

But after clicking, I get a bigass yellow page with the next error:

未处理的GridView'OrdersGridView'事件触发了RowDeleting.

The GridView 'OrdersGridView' fired event RowDeleting which wasn't handled.

推荐答案

在GridView中具有Delete键,甚至是CommandName为delete的常规按钮,都将自动尝试触发OnRowDeleting.您可以只添加它以使事情变得愉快,但不必执行任何操作,以免影响删除的行为.

Having a Delete button, or even a regular button in a GridView with a CommandName of delete, will automatically try to fire OnRowDeleting. You can just add it in to make things happy, but don't have it do anything so it doesn't affect the behavior of your delete.

您可以将OnRowDeleting添加到GridView:

You could add OnRowDeleting to your GridView:

<asp:GridView ID="OrdersGridView" runat="server" AutoGenerateColumns="False" onrowdeleted="OrdersGridView_RowDeleted" OnRowDeleting="OrdersGridView_RowDeleting">

然后在您的CodeBehind中添加:

And then in your CodeBehind add:

void OrdersGridView_RowDeleting (object sender, GridViewDeleteEventArgs e)
{
}

这篇关于GridView'OrdersGridView'引发了未处理的事件RowDeleting的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆