简体   繁体   中英

Delete Row From Gridview1

I am trying to delete a row in my gridview but im having a problem with the delete extension method.

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?)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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