Removing rows in asp.net

Posted by user279521 on Stack Overflow See other posts from Stack Overflow or by user279521
Published on 2010-04-27T12:15:50Z Indexed on 2010/04/27 12:23 UTC
Read the original article Hit count: 366

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET