I am using crystal reports in my asp.net application with vs 2010, It is working fine to print and export reports when I used the code on Page_Load event, but when I use the same code on a button click event, it returns empty data or blank report when I send it to printer or export to hard drive by using CR Viewer built-in buttons. I also used IsPotBack option on the page load and button click event before calling the code. But still failed to solve the problem.
Below is my source code for accessing the report:
Dim CN As New SqlConnection("connectionstring...")
CN.Open()
Dim ds As New DS_App_Profile.V_App_ProfileDataTable()
Dim cmd As New SqlCommand("SELECT * from TblApplicants where Applicant_Id=@id", CN)
cmd.Parameters.Add(New OleDbParameter("id", OleDbType.VarChar)).Value = Me.ComboBox1.SelectedValue
Dim adp As New SqlDataAdapter(cmd)
adp.Fill(ds)
'object of Report RptApplicantsByID
Dim rep As New RptApplicantsByID()
rep.SetDataSource(DirectCast(ds, DataTable))
Me.CrystalReportViewer1.ReportSource = rep
Me.CrystalReportViewer1.DataBind()