Creating a DotNetNuke Private Assembly with Crystal Reports - Part 4
page 3 of 4
by Eric Landes
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 20333/ 36

Displaying the Report

Let’s get to how to display our report.  Assuming that we have entered valid data in the parameter entries displaying in the panel, we need to press the now visible “View Report” button.  That button runs the code to set the login parameters, bind the report to a Crystal Report Document, and then bind that document to the Crystal Viewer on the page.     

Once the button is clicked, the btnViewReport_Click event fires.  We instantiate a new CRDisplayReport object and then set the reportname, dbname, servername, userid, and password property.  Then we call the method CreateReportToView, which returns a ReportDocument object that we bind to the Crystal Report Viewer.  See Code Listing 1 for the code.

Code Listing 1

CRDisplayReport oDisplay = new CRDisplayReport();
// This is where we put the selected reportname
and dbname etc.  For the article this is hardcoded.
oCRDoc = oDisplay.CreateReportToView(Request);

You can see from this code that the Crystal Report Viewer is bound to OCRDoc object.  This object is created from the CreateReportToView method.  The code for this method is found in Code Listing 2.

Code Listing 2

oReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); 
oDiscreteParam = new CrystalDecisions.Shared.ParameterDiscreteValue(); 
oDefaultValues = new CrystalDecisions.Shared.ParameterValues(); 
  int iCurrParm = 1;
(CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition oCRParam in oReport.DataDefinition.ParameterFields)

    oDiscreteParam.Value =
GetRequest(oCRParam.ParameterFieldName + iCurrParm.ToString(), oCRParam,

  return oReport;
catch (Exception e) 
  throw new
Exception("CRDisplayReport.CreateReportView experienced an error: " +

This code, also modified from a previous article, creates a Reportdocument oReport.  We load the report using the _reportname property.  iCurrParm follows the convention used previously that makes sure that all parameter names are unique.  This is how you can find the parameter names created in Part 3 of this series. 

We iterate through the all the parameters in the report using a foreach loop.  The value applied to each parameter (this assumes a DiscreteParamValue), is applied via the GetRequest method. 

The GetRequest method takes the parameter name, the parameter object, and the request object to find the appropriate parameters.  Because we need to find the controls via the request rather than the page.findcontrol method, we iterate through all the parameters in the request to find the correct parameter passed.

Once that parameter is found through the request object, it gets passed back to oDiscreteParam.Value.  After the parameters get applied, we need to pass the login information to the Report document.  This is done through the ApplyLoginInfo method shown in Code Listing 3.

Code Listing 3

oCRDb  = _oRpt.Database;
oCRTables = oCRDb.Tables;
oCRConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
oCRConnectionInfo.DatabaseName = _dbName;
oCRConnectionInfo.ServerName = _serverName;
oCRConnectionInfo.UserID = _userID;
oCRConnectionInfo.Password = _passWord;
oCRTable in oCRTables)
  oCRTableLogonInfo = oCRTable.LogOnInfo;
  oCRTableLogonInfo.ConnectionInfo =

This code simply applies the login information to the report document.  Once that’s done, the report object is returned back to the calling program.  In this case, that’s the User Control ReportsViewer btnViewReport_Click  event.  Once the object is bound to the viewer, the CrystalViewer objects Visible property is set to true.  Now the report is visible on the page!

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2023  |  Page Processed at 2023-10-03 6:01:24 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search