Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to print crystal report using button click event how should do thi process with c#??
i am using webforms .
Posted
Updated 21-Jan-13 21:25pm
v2
Comments
[no name] 22-Jan-13 3:26am    
You do not want the crystal report to show the data. When you click on button it should print directly that is what you want ?
Gopal Rakhal 22-Jan-13 3:37am    
plz clear your question little..
$ultaNn 22-Jan-13 6:44am    
i want to show the data frst then print with button click event

try this way ...

C#
ReportDocument oDocument = new ReportDocument();
oDocument.Load(Application.StartupPath + "//ReportPath//ReportName.rpt");
oDocument.SetDataSource(new DataSet()); // Added report data as dataset.
            
crviewer.ReportSource = oDocument;
crviewer.PrintReport();
 
Share this answer
 
v2
Comments
$ultaNn 29-Jan-13 7:14am    
i want to use data table instead of dataset
N Haque 29-Jan-13 8:53am    
you can try this-
DataTable dt = new DataTable();
// dt=Your DataTable;
DataSet ds = new DataSet();
ds.Tables.Add(dt);
oDocument.SetDataSource(ds);
In your button clcik write below code.

C#
crystalreport1 objReport1=new crystalreport1();
crystalreportviewer1.reportsource=objReport1;
 
Share this answer
 
v2
Comments
$ultaNn 23-Jan-13 1:08am    
its giving me this error on crystalreport1
The type or namespace name 'CrystalReport1' could not be found (are you missing a using directive or an assembly reference?)
josh-jw 23-Jan-13 1:11am    
give your crystal report name
$ultaNn 23-Jan-13 4:04am    
protected void Print(object sender, EventArgs e)
{
CrystalReport objReport1 = new CrystalReport();
CrystalReportViewer1.ReportSource = objReport1;

}

The type or namespace name 'CrystalReport' could not be found (are you missing a using directive or an assembly reference?) C:\inetpub\wwwroot\Mreport\crystal.aspx.cs

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