How to generate RDLC report using loop?

jewel 1,126 Reputation points
2025-02-06T16:01:01.2833333+00:00

I asked a question about this earlier here. But not getting the correct solution, I again asked for the help of experienced people.

I have shown a sample of my data below. I want to print this data on separate pages according to empid. I guess it can be done using a loop.

I have also attached an image to make it easier to understand.

  public IActionResult testPrint(int Ids)
  {
      List<tbl_order> orders = new List<tbl_order>()
      {
          // empid=1 and Customerid=1 Data
         new tbl_order{Id = 1,empid=1 ,Date = DateTime.Parse("2025,2,1"),productid=1,customerid=1,Qty=2,value=100},
         new tbl_order{Id = 2,empid=1 , Date = DateTime.Parse("2025,2,1"),produScreenshot (36).pngctid=2,customerid=1,Qty=1,value=200},
         
         // empid=1 and Customerid=2 Data
         new tbl_order{Id = 3,empid=1 , Date = DateTime.Parse("2025,2,1"),productid=3,customerid=2,Qty=3,value=1500},
         new tbl_order{Id = 4,empid=1 , Date = DateTime.Parse("2025,2,1"),productid=1,customerid=2,Qty=1,value=50},
         
         // empid=1 and Customerid=3 Data
         new tbl_order{Id = 5,empid=1 , Date = DateTime.Parse("2025,2,1"),productid=2,customerid=3,Qty=2,value=400},
            
         // empid=1 and Customerid=4 Data
         new tbl_order{Id = 6,empid=1 , Date = DateTime.Parse("2025,2,1"),productid=3,customerid=4,Qty=4,value=2000},
         new tbl_order{Id = 7, empid=1 ,Date = DateTime.Parse("2025,2,1"),productid=4,customerid=4,Qty=2,value=3000},
         new tbl_order{Id = 8,empid=2 ,Date = DateTime.Parse("2025,2,1"),productid=1,customerid=5,Qty=4,value=200},
         new tbl_order{Id = 9,empid=2 , Date = DateTime.Parse("2025,2,1"),productid=2,customerid=5,Qty=6,value=1200},
         new tbl_order{Id = 10,empid=2 , Date = DateTime.Parse("2025,2,1"),productid=3,customerid=6,Qty=1,value=500},
      };
  var Printdata = (from a in orders.Where(x => x.empid == 1)

                   group a by a.customerid into g

                   select new

                   {

                       customerid = g.Key,

                       productid = g.Select(x => x.productid),

                       Qty = g.Select(x => x.Qty),

                       value = g.Select(x => x.value),

                   }).ToList();



  var parameterdata = orders.Where(x => x.empid == 1).FirstOrDefault().customerid;

  String customerid=parameterdata.ToString();

  int extension = (int)(DateTime.Now.Ticks >> 10);

  String path = _webHostEnvironment.WebRootPath + @"\Reports\xyz.rdlc";

  Dictionary<String, string> parmeter = new Dictionary<String, string>();

  parmeter.Add("customer", customerid);

      LocalReport localreport = new LocalReport(path);

      localreport.AddDataSource("DataSet1", Printdata);

      var report = localreport.Execute(RenderType.Pdf, extension, parmeter, "");

  return File(report.MainStream, "application/pdf");

}

  public class tbl_order
  {
      public int Id { get; set; }
      public DateTime Date { get; set; }
      public int empid { get; set; }
      public int Qty { get; set; }
      public int productid { get; set; }
      public Decimal value { get; set; }
      public int customerid { get; set; }
  }

Screenshot (36)

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,773 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.