C# 如何使用网格中的按钮动态删除/编辑GridView中的行

C# 如何使用网格中的按钮动态删除/编辑GridView中的行,c#,asp.net,gridview,C#,Asp.net,Gridview,如何使用GridView本身中的按钮动态删除/编辑GridView中的行 我尝试了行删除事件进行删除&行编辑进行编辑。但是,我无法获得所需的结果 使用VS2005 asp.net C#2.0 下面是我在行删除事件中尝试的内容 protected void GridViewFRM_RowDeleting(object sender, GridViewDeleteEventArgs e) { if (connection.State == ConnectionState.Cl

如何使用
GridView
本身中的
按钮动态删除/编辑
GridView
中的行

我尝试了
行删除
事件进行删除&
行编辑
进行编辑。但是,我无法获得所需的结果

使用VS2005 asp.net C#2.0

下面是我在
行删除
事件中尝试的内容

protected void GridViewFRM_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        if (connection.State == ConnectionState.Closed)
        {
            connection.Open();
        }
        OracleCommand OLCOM3 = new OracleCommand();
        OLCOM3.CommandText = "Delete from FORUM WHERE QUESTION='" + GridViewFRM.DataKeys[e.RowIndex].Values[0].ToString() + "'";
        OLCOM3.ExecuteNonQuery();
        DisplayUserData();
    }

为“编辑和删除”按钮指定命令名

<asp:ImageButton runat="server" id="editBtn" commandName="Edit"></asp:ImageButton>

删除操作相同,您可以按照以下操作

根据需要更改命令名。但不要使用“删除/编辑”,因为我们使用的是行命令而不是编辑/删除命令