简体   繁体   English

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

[英]The GridView 'OrdersGridView' fired event RowDeleting which wasn't handled

I'm getting this error over and over again. 我一遍又一遍地得到这个错误。

Loading the data into the GridView works, but when I want to delete a row I'm getting that error. 将数据加载到GridView中可以正常工作,但是当我想删除一行时,我收到了该错误。

<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# codebehind - I'm not really deleting the row from the database but it's a test: C#codebehind - 我并没有真正删除数据库中的行,但这是一个测试:

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: 但点击后,我得到一个bigass黄页,下一个错误:

The GridView 'OrdersGridView' fired event RowDeleting which wasn't handled. GridView的'OrdersGridView'触发了未处理的事件RowDeleting。

Having a Delete button, or even a regular button in a GridView with a CommandName of delete, will automatically try to fire OnRowDeleting. 删除按钮,甚至是删除了CommandName的GridView中的常规按钮,将自动尝试触发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. 您可以添加它以使事情变得愉快,但是没有它做任何事情,因此它不会影响删除的行为。

You could add OnRowDeleting to your GridView: 您可以将OnRowDeleting添加到GridView:

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

And then in your CodeBehind add: 然后在你的CodeBehind中添加:

void OrdersGridView_RowDeleting (object sender, GridViewDeleteEventArgs e)
{
}

将您的行命令名称从删除更改为任何其他类似deleterecord

It looks like you are handling the "onrowdeleted" event, not the "RowDeleting" event 看起来您正在处理“onrowdeleted”事件,而不是“RowDeleting”事件

in your markup, change: onrowdeleted="OrdersGridView_RowDeleted" 在你的标记中,更改:onrowdeleted =“OrdersGridView_RowDeleted”

to RowDeleting="OrdersGridView_RowDeleting" to RowDeleting =“OrdersGridView_RowDeleting”

Look a the docs for this event: you will also see that your handler's signature will need to change: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdeleting.aspx your new handler will look someting like this: 查看此事件的文档:您还将看到您的处理程序的签名需要更改: http//msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdeleting.aspx你的新处理程序看起来像这样:

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

the RowDeleting event happens, then the onrowdeleted event. 发生RowDeleting事件,然后是onrowdeleted事件。 The RowDeleting probally lets you Cancel the event. RowDeleting可能会让您取消活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM