Delete a Specify Row from a DataTable

1

How can I delete a specified row from a DataTable and then reload a ViewState with the rest of the rows left? I have the following case below, but I am not able to delete 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;
    }
    
asked by anonymous 25.11.2015 / 14:51

1 answer

3

You can do this:

table.Rows[indice].Delete(); 
table.AcceptChanges();
    
25.11.2015 / 14:55