I'm using Crystal 9 and VB.Net in an .aspx page. The page has a CrystalReportViewer, and everytime the page loads, it loads the report, logs on, assigns the most recent RecordSelectionFormula, and then does DataBind.
The webpage also has a user control that creates and stores the most recent RecordSelectionFormula. The user control stores a reference to the CrystalReportViewer and the CrystalReportDocument. When the user clicks the user control's submit button, the user control reassembles the RecordSelectionFormula, applies it to the CrystalReportViewer and CrystalReportDocument, and does DataBind again.
The RecordSelectionFormula is applied and displayed correctly in the CrystalReportViewer; however, when the user clicks on the CrystalReportViewer's print button, selects the pages to print, and then clicks Print again, the pdf version of the report that Crystal makes displays all the data, and doesn't have the RecordSelectionFormula applied.
Thanks for your help!
frmCrystalReportViewer.aspx.vb
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
' Remember which report to load later
txtReportName.Text = Request.QueryString("ReportName"
End If
' Initialize Crystal Report Viewer
Dim ReportDisplayName As String
Try
ReportDisplayName = InitReport()
PageTitle.InnerText = ReportDisplayName
Catch ex As Exception
lblTest.Text = ex.Message
End Try
' Set up search query stuff
SearchQuery1.SearchQueryTitle = ReportDisplayName
SearchQuery1.SubmitButtonText = "Get My Report"
SearchQuery1.SetCrystalReportViewerToBind(CrystalReportViewer1)
SearchQuery1.SetCrystalReportDocumentToBind(crReportDocument)
End Sub
Private Function InitReport() As String
Dim sPhysicalPath As String = HttpContext.Current.Request.ServerVariables("APPL_PHYSICAL_PATH"
Dim ReportDisplayName As String
Dim crTableLogOnInfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
Dim crTableCurrent As CrystalDecisions.Shared.TableLogOnInfo
Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
crReportDocument.Load(sPhysicalPath & "\Reports\rptArbitrationReport.rpt", OpenReportMethod.OpenReportByDefault)
For Each crTable In crReportDocument.Database.Tables
crTableCurrent = crTable.LogOnInfo
With crTableCurrent.ConnectionInfo
.ServerName = "server"
.DatabaseName = "database"
.UserID = "dbuser"
.Password = "pword"
End With
crTable.ApplyLogOnInfo(crTableCurrent)
Next crTable
crReportDocument.RecordSelectionFormula = ""
crReportDocument.RecordSelectionFormula = SearchQuery1.CrystalReportViewerSearchCriteria
CrystalReportViewer1.ReportSource = crReportDocument
CrystalReportViewer1.SelectionFormula = SearchQuery1.CrystalReportViewerSearchCriteria
CrystalReportViewer1.DataBind()
ReportDisplayName = "Arbitration"
Return ReportDisplayName & " Report"
End Function
User Control - SearchQuery.ascx.vb
This is called from SearchQuery's btnSubmit_OnClick
Public Sub DoSearch()
' Set the selection formula for a Crystal Reports Viewer
' Assumes that the report viewer has already had its logon info set
If Not IsNothing(ReportViewerToBind) Then
RptDocToBind.RecordSelectionFormula = GetCrystalReportViewerSearchCriteria()
ReportViewerToBind.SelectionFormula = GetCrystalReportViewerSearchCriteria()
ReportViewerToBind.DataBind()
ReportViewerToBind.Visible = True
End If
End Sub
The webpage also has a user control that creates and stores the most recent RecordSelectionFormula. The user control stores a reference to the CrystalReportViewer and the CrystalReportDocument. When the user clicks the user control's submit button, the user control reassembles the RecordSelectionFormula, applies it to the CrystalReportViewer and CrystalReportDocument, and does DataBind again.
The RecordSelectionFormula is applied and displayed correctly in the CrystalReportViewer; however, when the user clicks on the CrystalReportViewer's print button, selects the pages to print, and then clicks Print again, the pdf version of the report that Crystal makes displays all the data, and doesn't have the RecordSelectionFormula applied.
Thanks for your help!
frmCrystalReportViewer.aspx.vb
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
' Remember which report to load later
txtReportName.Text = Request.QueryString("ReportName"
End If
' Initialize Crystal Report Viewer
Dim ReportDisplayName As String
Try
ReportDisplayName = InitReport()
PageTitle.InnerText = ReportDisplayName
Catch ex As Exception
lblTest.Text = ex.Message
End Try
' Set up search query stuff
SearchQuery1.SearchQueryTitle = ReportDisplayName
SearchQuery1.SubmitButtonText = "Get My Report"
SearchQuery1.SetCrystalReportViewerToBind(CrystalReportViewer1)
SearchQuery1.SetCrystalReportDocumentToBind(crReportDocument)
End Sub
Private Function InitReport() As String
Dim sPhysicalPath As String = HttpContext.Current.Request.ServerVariables("APPL_PHYSICAL_PATH"
Dim ReportDisplayName As String
Dim crTableLogOnInfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
Dim crTableCurrent As CrystalDecisions.Shared.TableLogOnInfo
Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
crReportDocument.Load(sPhysicalPath & "\Reports\rptArbitrationReport.rpt", OpenReportMethod.OpenReportByDefault)
For Each crTable In crReportDocument.Database.Tables
crTableCurrent = crTable.LogOnInfo
With crTableCurrent.ConnectionInfo
.ServerName = "server"
.DatabaseName = "database"
.UserID = "dbuser"
.Password = "pword"
End With
crTable.ApplyLogOnInfo(crTableCurrent)
Next crTable
crReportDocument.RecordSelectionFormula = ""
crReportDocument.RecordSelectionFormula = SearchQuery1.CrystalReportViewerSearchCriteria
CrystalReportViewer1.ReportSource = crReportDocument
CrystalReportViewer1.SelectionFormula = SearchQuery1.CrystalReportViewerSearchCriteria
CrystalReportViewer1.DataBind()
ReportDisplayName = "Arbitration"
Return ReportDisplayName & " Report"
End Function
User Control - SearchQuery.ascx.vb
This is called from SearchQuery's btnSubmit_OnClick
Public Sub DoSearch()
' Set the selection formula for a Crystal Reports Viewer
' Assumes that the report viewer has already had its logon info set
If Not IsNothing(ReportViewerToBind) Then
RptDocToBind.RecordSelectionFormula = GetCrystalReportViewerSearchCriteria()
ReportViewerToBind.SelectionFormula = GetCrystalReportViewerSearchCriteria()
ReportViewerToBind.DataBind()
ReportViewerToBind.Visible = True
End If
End Sub