Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a crystal report which i want to print on button click.I have the following code for printing on print button click event

C#
protected void Page_Init(object sender, EventArgs e)
     {
         if (!this.IsPostBack)
         {

         }
         else
         {
             if (Session["reportdocument"].ToString() != string.Empty || Session["reportdocument"] != null)
             {
                 ReportDocument reportdocument = (ReportDocument)Session["reportdocument"];
                 CrystalReportViewer1.ReportSource = reportdocument;
                 CrystalReportViewer1.DataBind();
             }
         }
     }


protected void ButtonPrint_Click(object sender, EventArgs e)
{
try
{
CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
CrystalReportViewer1.SeparatePages = false;
var printeInstaled = System.Drawing.Printing.PrinterSettings.InstalledPrinters;

string printerName = "";
foreach (var item1 in printeInstaled)
{
printerName = item1.ToString();
break;
}
PrintDocument myPrinter = new PrintDocument();
ReportDocument rptprint = (ReportDocument)Session["reportdocument"];
rptprint.PrintOptions.PrinterName = printerName;
rptprint.PrintToPrinter(1, false, 0, 0);
rptprint.PrintOptions.PaperOrientation = PaperOrientation.DefaultPaperOrientation;
rptprint.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;

}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

}
I am able to disable paging by using CrystalReportViewer1.SeparatePages = false;
But the problem is it prints only first page.In print preview of one note i can see it.And also if i disable paging and try to print pages one by one..it still prints only the first age despite if i am on 2nd or 3rd page.Is this the problem of rebinding report or something?
Why id this happening?Can anyone help me out ?. All these problems i m facing before publishing my app on iis. After publishing the print code is not working at all .
Posted
Updated 12-Feb-14 2:44am
v4
Comments
thatraja 11-Feb-14 8:59am    
Share other code in your question

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