Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I have an issue that multiple print of label based on number box.
scenario is : If we have number of box is 5.
We need 5 label to be print like 1/5,2/5 ...5/5.

Is it possible?

pls advice me
Thank you

Maideen

What I have tried:

It is my Code. it is working Fine. But can print only one label

ASP.NET
ReportViewer1.ProcessingMode = ProcessingMode.Local
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("lbl_Print.rdlc")
        Dim dsReport As label_DataSet = GetData_SP()
        Dim datasource As New ReportDataSource("DataSet1", dsReport.Tables(1))
        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(datasource)
        ReportViewer1.LocalReport.Refresh()
        ReportViewer1.LocalReport.EnableExternalImages = True
Posted
Updated 10-Jul-23 22:44pm
v2

1 solution

You can use a 'For' loop to iterate from 1 to the value of 'numLabels' (which is 5 in this case). I have no idea what box you are speaking of, I named it 'PrintBox' -

ASP.NET
' Assuming you have a variable named 'PrintBox' with the value 5, if not replace this with whatever 'box' is...

' Calculate the number of labels to print based on the value of PrintBox
Dim numLabels As Integer = 5

For i As Integer = 1 To numLabels
    ' Create a new printjob of the label for each label
    Dim dsReport As label_DataSet = GetData_SP()

    ' Set the value of the PrintBox for the current label
    dsReport.Tables(1).Rows(0)("PrintBox") = i

    ' Set up the report viewer for the current label
    ReportViewer1.ProcessingMode = ProcessingMode.Local
    ReportViewer1.LocalReport.ReportPath = Server.MapPath("lbl_Print.rdlc")
    Dim datasource As New ReportDataSource("DataSet1", dsReport.Tables(1))
    ReportViewer1.LocalReport.DataSources.Clear()
    ReportViewer1.LocalReport.DataSources.Add(datasource)
    ReportViewer1.LocalReport.Refresh()
    ReportViewer1.LocalReport.EnableExternalImages = True

    ' Print the label
    Dim printerSettings As New System.Drawing.Printing.PrinterSettings()
    Dim pageSettings As New System.Drawing.Printing.PageSettings()
    ReportViewer1.SetPageSettings(pageSettings)
    ReportViewer1.PrinterSettings = printerSettings
    ReportViewer1.PrintToPrinter(printerSettings.Copies, printerSettings.Collate, 0, 0)
Next


You should really get into the habit of naming all of your controls, variables etc with meaningfull names. This will save you a ton of work in the future when you have to try and decipher what each 'ReportViewer1, TextBox1, x, z' etc means or what their functions are - ASP>NET General Naming Conventions[^]
 
Share this answer
 
v3
Comments
Maideen Abdul Kader 16-Jul-23 19:07pm    
Thank you Mr.Andre.
Now error is in this line "ReportViewer1.LocalReport.PrintToPrinter()"
Pls advice me.
Thank you
Andre Oosthuizen 17-Jul-23 4:20am    
You're welcome.

Quote:Now error is in this line "ReportViewer1.LocalReport.PrintToPrinter()" does not help me at all, I cannot see your screen so I cannot guess what the error is? Apart from ASP.NET, are you using the print methods in a Windows Forms applications? Info is worth gold. :)
Maideen Abdul Kader 17-Jul-23 21:18pm    
hi Andre. the error is PrintToPrinter is not a member of 'ReportViewer1.LocalReport'
using below code, usually I am using for other reports
ReportViewer1.LocalReport.Refresh()
ReportViewer1.LocalReport.EnableExternalImages = True
it will shows only one label whether "Print box" is more than one.
pls advice me
Thank you
maideen
Andre Oosthuizen 18-Jul-23 3:49am    
The print method I supplied was for windows apps, sorry. For ASP.NET you can use the code I just added to the solution.

In the updated code, after setting up the report viewer and refreshing your local report, create an instance of 'PrinterSettings' and 'PageSettings' to configure the printing options, remember that your process is automated so no user interactions will be available.

You then assign the 'PageSettings' to your 'ReportViewer' using the 'SetPageSettings' method. This makes sure that the report is printed using your specific page settings.

Next, assign the 'PrinterSettings' to the 'ReportViewe'r and call the 'PrintToPrinter' method, passing the number of copies to print, the collate setting, and the start page and end page parameters (in this case, printing all pages with 0 as the start and end page).

This will automatically print the labels for each number without requiring manual intervention from your user.

Another method to consider (the most used) is to create a pdf document, let user download it and then print the pdf.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900