I am attempting to remove rows on my asp.net page using the following code:
try
{
Table t = (Table)Page.FindControl("Panel1").FindControl("tbl");
foreach (TableRow tr in t.Rows)
{
t.Rows.Remove(tr);
}
}
catch (Exception e)
{
lblErrorMessage.Text = "Error - RemoveDynControls - " + e.Message;
}
however, I am getting an error on the (when the code loops the second time around) "Collection was modified; enumeration operation may not execute."
Any ideas regarding what is causing the error message?