简体   繁体   English

从Gridview1删除行

[英]Delete Row From Gridview1

I am trying to delete a row in my gridview but im having a problem with the delete extension method. 我正在尝试在gridview中删除一行,但是我在使用delete扩展方法时遇到问题。

Error im getting: 错误即时消息:

'System.Web.UI.WebControls.GridViewRow' does not contain a definition for 'Delete' and no extension method 'Delete' accepting a first argument of type 'System.Web.UI.WebControls.GridViewRow' could be found (are you missing a using directive or an assembly reference?) 'System.Web.UI.WebControls.GridViewRow'不包含'Delete'的定义,并且找不到扩展方法'Delete'接受类型为'System.Web.UI.WebControls.GridViewRow'的第一个参数(您是缺少using指令或程序集引用?)

Here is my code: 这是我的代码:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName.Equals("Submit"))
    {
        GridViewRow oItem = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
        int RowIndex = oItem.RowIndex;
        GridView1.Rows[RowIndex].Delete();
    }
}

Try to do this using a different approach by looping thru the DataGridView's Selected Rows 尝试使用另一种方法通过遍历DataGridView的选定行来做到这一点

if (e.CommandName.Equals("Submit"))
{
    GridView1.DeleteRow(GridView1.SelectedIndex)
    //you could null the datasource here and reassign if necessary here prior to calling DataBind()
    GridView1.DataBind();
}

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

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