I have an html table in blazor that fills up looping over a list (columns reduced to show relevant code)
@foreach (var line in lines)
{@{ var linenumber = lines.IndexOf(line)}
<td>
<DDItems @bind-Binder="line.item"></DDItems>
</td>
<td>
<button type="button" @onclick="@(() => removeRow(linenumber))">Remove</button>
</td>
}
@Code{
private List<TransactionSALine> lines = new List<TransactionSALine>();
private async Task removeRow(int linenumber)
{
lines = lines.Where(u => lines.IndexOf(u) != linenumber).ToList());
}
}
When I remove one of the rows from the table, item selected in other rows gets changed.
- I have tried to use an array instead of the list but that didn't help.
- Tried to change the removerow() method using Linq and RemoveAt(). Doesn't change the result.
Before removing the row with Product "pencil":

After removing the product "pencil":
