0

can someone one help me, i have rdlc textbox, and i created parameter to pass it into report viewer using for loop. Is this possible?

the result in report viewer should be like this:

Page 1: index_0
Page 2: index_1
Page 3: index_2

each index in different page because i'm using for loop..

Here is my code:

   private void button1_Click(object sender, EventArgs e)
        {

            reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
            var setup = reportViewer1.GetPageSettings();
            setup.Margins.Top = new System.Drawing.Printing.Margins().Top = 25;
            setup.Margins.Bottom = new System.Drawing.Printing.Margins().Bottom = 65;
            reportViewer1.SetPageSettings(setup);

            ReportParameter[] data = new ReportParameter[] { };

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    data = new ReportParameter[3];
                    data[i] = new ReportParameter("myData", "index_" + i);
                    this.reportViewer1.LocalReport.SetParameters(data);
                }
                catch (Exception ex)
                {
                    return;
                }
            }
            this.reportViewer1.RefreshReport();
        }

please any help thanks in advance..

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
Robert
  • 59
  • 1
  • 9
  • You havent explained what is going wrong. – Amogh Sarpotdar Jul 12 '22 at 17:15
  • @AmoghSarpotdar what going wrong is that when I try reportviewer refresh i get only index_0 print in the first page and the other page not showing up.. you get me? – Robert Jul 12 '22 at 20:43
  • I am guessing you are running into exception when processing the second element. First of all catching generic exception is bad practice. You should change that statement ... catch(Exception ex) to specific exception that is relevant to your code. Next, you are not taking any action inside the catch block. Put some console.WriteLine statement that will print exception message. This way you have something to look at when debugging. Ideally you should have log statements in there. Implement these changes and see how it works. Not sure whats wrong with your first element's data atm... – Amogh Sarpotdar Jul 13 '22 at 00:23
  • I am talking about the code and how to accomplish it, not about exceptions... because we don't have any error right now! Can you focus on the idea and how to implement it? Thx. – Robert Jul 13 '22 at 08:33

0 Answers0