Hai, I'm Using VS2010,
I'm using crystal report in my web page. It's executed successfully and show my records.
But, I'm using code for print that crystal report record. The problem is it's automatically print that page when I execute my Report Page.
I don't want that, first Crystal Report show the record, when the user Press the print button on Crystal Report Tool Bar, and then Printing is start....
See my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public partial class Report : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
txtID.Text = Session["ID"].ToString();
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("~/stdCR.rpt"));
std ds = GetData("select * from empdet");
crystalReport.SetDataSource(ds);
CrystalReportViewer1.ReportSource = crystalReport;
crystalReport.Refresh();
crystalReport.PrintOptions.PaperOrientation = PaperOrientation.Portrait;
crystalReport.PrintOptions.PaperSize = PaperSize.PaperA4;
crystalReport.PrintToPrinter(1,false,0,0);
}
private std GetData(string query)
{
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection("Data Source=SERVICETEAM-PC;Initial Catalog=example;User ID=sa;Password=kavi"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (std ds = new std())
{
sda.Fill(ds, "DataTable1");
return ds;
}
}
}
}
}