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 8434561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:41:25+00:00 2026-06-10T06:41:25+00:00

I am passing some parameters through a silverlight childwindow to a aspx page which

  • 0

I am passing some parameters through a silverlight childwindow to a aspx page which hosts my crystal report in a pdf. It is a printing function for the stickers on file folders. I have created the crystal report to resemblr the template of the printout sheet. I have created a stored procedure that gets the information from the database to print the labels.

The main thing is, I created a skip function so the user can skip the approiate amount of labels to print on the next one. I have expanded it so the user can print just one label or multiple labels.

So I thought to use a foreach loop so one label comes in, it prints one label, multiple labels come in, it prints the multiple. Except when i run it, i get the error Collection was modified, enumeration operation might not execute. Here is the create table and skip code.

try
        {
            _skip = Request.QueryString["_skip"];
            _Report = Request.QueryString["_Report"];
            _jobnum = Request.QueryString["_jobnum"];
            jobnum1 = Request.QueryString["jobnum1"];
            jobnum2 = Request.QueryString["jobnum2"];
            addedBy = Request.QueryString["addedBy"];
            date = Request.QueryString["date"];

            // Create Table
            tb = new DataTable();
            tb.Columns.Add("FileName", Type.GetType("System.String"));
            tb.Columns.Add("PieceType", Type.GetType("System.String"));
            tb.Columns.Add("PieceNumber", Type.GetType("System.String"));
            tb.Columns.Add("JobNumber", Type.GetType("System.String"));
            tb.Columns.Add("OpenDate", Type.GetType("System.String"));
            tb.Columns.Add("Market", Type.GetType("System.String"));
            tb.Columns.Add("MarketYear", Type.GetType("System.String"));
            tb.Columns.Add("BusinessName", Type.GetType("System.String"));

            int length;
            int.TryParse(_skip, out length);
            length = Convert.ToInt16(_skip);

            // Populate Blank Rows to skip labels
            for (int i = 0; i < length; i++)
            {
                dr = tb.NewRow();
                tb.Rows.Add(dr);
            }

            //Create rows depending on how many jobs come in.
            foreach (DataRow drJob in tb.Rows)
            {
                dr = tb.NewRow();
                dr["FileName"] = drJob["PieceType"].ToString() + drJob["PieceNumber"].ToString();
                dr["PieceType"] = drJob["PieceType"].ToString();
                dr["PieceNumber"] = drJob["PieceNumber"].ToString();
                dr["JobNumber"] = drJob["JobNumber"].ToString();
                dr["OpenDate"] = drJob["OpenDate"].ToString();
                dr["Market"] = drJob["Market"].ToString();
                dr["MarketYear"] = drJob["MarketYear"].ToString();
                dr["BusinessName"] = drJob["BusinessName"].ToString();
                tb.Rows.Add(dr);
            }
            ShowPDF(tb);
        }

        catch (Exception ex)
        {
        }

So during the catch, it displays that error. I tried to add a .ToList() at the end of the tb.Rows but it is not supported. I search around for a bit and tried the following code

foreach (DataRow drJob in tb.Rows.Cast<DataRow>().ToList())

This part actually went through, but generated blank labels, and created labels for how many I chose to skip.(It would skip ‘9’ rows/tables and then generate ‘9’ labels for print)

My question is, how can I modify the foreach loop to 1) not have that error and 2) produce the correct amount of labels, whether its one or ten. I am guessing that modifying the length(skip) is causing the colletion was modified, but if so, how can I create a seperate list for it(.ToList()) while adjusting for the difference of parameters. They are passed in through two different ways to this same aspx btw.

  • 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-10T06:41:26+00:00Added an answer on June 10, 2026 at 6:41 am

    This is how I would do it:

            //Create rows depending on how many jobs come in.
            List<DataRow> newRows = new List<DataRow>();
    
            foreach (DataRow drJob in tb.Rows)
            {
                dr = tb.NewRow();
                dr["FileName"] = drJob["PieceType"].ToString() + drJob["PieceNumber"].ToString();
                dr["PieceType"] = drJob["PieceType"].ToString();
                dr["PieceNumber"] = drJob["PieceNumber"].ToString();
                dr["JobNumber"] = drJob["JobNumber"].ToString();
                dr["OpenDate"] = drJob["OpenDate"].ToString();
                dr["Market"] = drJob["Market"].ToString();
                dr["MarketYear"] = drJob["MarketYear"].ToString();
                dr["BusinessName"] = drJob["BusinessName"].ToString();
                newRows.Add(dr);
            }
    
            foreach(DataRow dr in newRows)
                 tb.Rows.Add(dr);
    

    This way you’re not attempting to modify the Rows collection during the iteration, you just build up the new rows you want and add them to the collection all at once.

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

Sidebar

Related Questions

I'm currently passing some date-time info to a web page using url parameters, which
iam passing some parameters in url to a page through curl, but to my
I'm passing some parameters to a CR report programatically and it was working fine,
Am passing some parameters through in Struts2, and am getting below error when there
I am having some trouble passing parameters for a template function trough a non-template
I'm having a problem passing some parameters to a partial. No matter what I've
I'm using simple_form for a form and passing in some URL parameters to prepopulate
I am Rails newbie and having some trouble passing parameters to form. I have
I am having some difficulties passing in parameters to my controller. I created an
I have read some posts on here about not mixing parameters when passing into

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.