Delete a specified line from a Datatable

Asked

Viewed 2,096 times

1

How can I delete a specific line from a DataTable and then reload a ViewState with the rest of the lines that stayed? I have the following case below, but am not getting deleta directly from DataTable.

protected void rdItens_DeleteCommand(object sender, GridCommandEventArgs e)
    {
        string ID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"].ToString();
        DataTable table = (DataTable)ViewState["ItensGrid"];

        var linha = table.Rows.Find(ID);
        linha.Delete();

        ViewState["ItensGrid"] = table;
    }

1 answer

3


You can do it like this:

table.Rows[indice].Delete(); 
table.AcceptChanges();
  • the [Indice] in this case is my ID?

  • 1

    Yeah, I put it as an index just to make it a little bit clearer.

  • Perfect, I just didn’t understand what the AcceptChanges() ago.

  • Acceptchanges() accepts modifications.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.