gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 09:02:29 27 4
gpt4 key购买 nike

我一遍又一遍地遇到这个错误。

将数据加载到 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# 代码隐藏 - 我并没有真正从数据库中删除该行,但它是一个测试:

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;
}
}

但是在点击之后,我得到了一个带有下一个错误的大黄页:

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

最佳答案

在 GridView 中有一个 Delete 按钮,甚至是 CommandName 为 delete 的常规按钮,将自动尝试触发 OnRowDeleting。您可以只添加它来让事情变得愉快,但不要让它做任何事情,这样它就不会影响您的删除行为。

您可以将 OnRowDeleting 添加到您的 GridView:

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

然后在您的代码隐藏中添加:

void OrdersGridView_RowDeleting (object sender, GridViewDeleteEventArgs e)
{
}

关于c# - GridView 'OrdersGridView' 触发了未处理的事件 RowDeleting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3544039/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com