繁体   English   中英

GridView''触发了未处理的事件RowUpdating。 ASP.NET背后的C#代码

[英]The GridView ' ' fired event RowUpdating which wasn't handled. C# code behind asp.net

在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可以解决问题。

提前致谢,

蒂姆·A

ASP.NET中的GridView具有一些内置命令DeletedUpdate等。发生的是您的按钮的命令名称为Update ,而Gridview劫持了您的该命令并触发了RowUpdating事件而不是RowEditing事件。 将按钮命令名称更改为Edit ,并使用RowEditing事件。

如果要使用Row_Command事件进行编辑, Row_Command按钮命令名“ Update”用于更新,而将“ Delete”用于删除。 而是分别使用Edit或UP和Del。

暂无
暂无

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

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