Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8295429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:35:05+00:00 2026-06-08T14:35:05+00:00

I think this problem is related to Reference Types, and my lack of understanding

  • 0

I think this problem is related to Reference Types, and my lack of understanding of these …

So I have dynamically created ASP.Net Tables (as in Web.UI.WebControls.Table, not the database variety)
These can have anything from one row with one cell with text, to a whole series of nested tables and controls, depending on the clients.

I need to loop through each TableRow, if a certain condition is met then I copy that row to a 2nd Table object. Here’s a simplified bit of the code.

        Table xTblComplete = (passed in as parameter) // original & complete table
        Table xTblTemp = new Table();  // gets built dynamically with specific rows

        foreach (TableRow xThisRow in xTblComplete.Rows)
        { 
            if (xThisRow.Cells.Count > 0)
            {
                if (certain condition met)
                {
                    xTblTemp.Rows.Add(xThisRow);
                }
            }
        }

Where I come unstuck is that the foreach (row in table.rows) throws an error when I try to add the TableRow to Table2. I get the error “Collection was modified; enumeration operation may not execute. ”
This makes sense, in that I should be making a COPY of that Table Row to add.

Can anyone advise on how this is done? I’ve scanned MSDN and the forums for general copying-of-reference types, but they all seem to point to using ICloneable , which I believe I’m unable to do as this isn’t my class.

Am hoping this is something small and fundamental I’m missing out on, thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:35:07+00:00Added an answer on June 8, 2026 at 2:35 pm

    Thanks Ulises, your answers were helpful, unfortunately the complexity of these tables procluded a simple loop & copy contents. By that I mean that there were cells that might possibly have had 5 levels of nested tables, with any number of web controls inside each. Yep, a CSS perfectionist would retch at the idea of so many nested tables, but it’s what had to be done!!

    In the end I utilized a while(bln) loop, examining xTblComplete.Rows[0] each time.

    If it met the condition , I would copy it to xTmpTable, which also removed it from xTblComplete.

    If it failed the condition, I would remove it myself ( xTblComplete.Rows.Remove(xTblComplete.Rows[0]);

    This way Rows[0] would always be the next to process.
    After each Loop I checked the bln for more rows to process, if none then the loop would exit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is related to this post . I think I am having problem with
I am trying to solve this problem http://www.spoj.pl/problems/PEBBMOV/ . I think I have the
I have asked questions related to this before, but I think I was framing
I have a problem which I think is related to forward declarations, but perhaps
I think that this problem can be sorted using reflection (a technology which I'm
I think this might be a problem with the theme I'm using ( Nitobe
I think this is a pretty straightforward problem but... var outerHeight = $('.profile').outerHeight(); $(#total-height).text(outerHeight
This problem is happening for me on IE8 and Chrome which makes me think
I think I read every single web page relating to this problem but I
I've been working on this problem most of the morning and I think I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.