GridView“ ”引发了未处理的事件 RowUpdating。 asp.net 背后的 C# 代码

2023-12-04

Stackoverflow和其他网站上也有类似的问题,但我似乎错过了一些东西。

我有一个 GridView 绑定到来自数据库的 DataTable。我的目标是使用调用以下方法的同一行中的按钮更新当时的一行。

        protected void TestsToBeDone_RowUpdating(object sender, GridViewEditEventArgs e)
    {
        SqlConnection myConnection = getConnection();
        myConnection.Open();

        int index = Convert.ToInt32(e.NewEditIndex);

        GridViewRow selectedRow = TestsToBeDone.Rows[index];
        TableCell LABAVIDc = selectedRow.Cells[1];
        int LABAVID = Convert.ToInt32(LABAVIDc.Text);

        TableCell assistentc = selectedRow.Cells[5];

        string query = "UPDATE Labaanvraag " +
                       "SET Status='4' "+
                                 "WHERE LABAVID ='"+LABAVID+"'";
        }

        SqlCommand commandZ = new SqlCommand(query, myConnection);
        commandZ.ExecuteNonQuery();            

        myConnection.Close();

        SetPatientTestGrid(Session["PATID"], e);
    }

它是从这里调用的:

    <asp:GridView ID="TestsToBeDone" runat="server" EnableModelValidation="True" OnRowEditing="TestsToBeDone_RowUpdating">
    <Columns>
        <asp:ButtonField ButtonType="Button" CommandName="Update" 
            HeaderText="Afgenomen" ShowHeader="True" Text="Afgenomen" />
    </Columns>
</asp:GridView>

在我的第一次尝试中,我在代码后面有一个带有 GridViewCommandEventArgs 的 OnRowCommand 。

但它仍然抛出相同的异常,尽管我在几个网站上读到将其更改为 OnRowEditing 和 GridViewEditEventArgs 可以解决问题。

提前致谢,

Tim A


ASP.NET 中的 GridView 有一些内置命令 -Deleted, Update等等。发生的情况是您的按钮的命令名称为Update,并且 Gridview 正在从您那里劫持它并发射一个RowUpdating事件而不是你的RowEditing事件。将按钮命令名称更改为Edit,并使用RowEditing event.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

GridView“ ”引发了未处理的事件 RowUpdating。 asp.net 背后的 C# 代码 的相关文章

随机推荐