To display these parameters, we need to instantiate
CRParameterPanel and call the method that dynamically creates the controls for
each of the parameters. These controls will hold user input values, then allow
the users to view the report based on those parameters.
The user clicks a select button column on the datagrid with
the Text “View.” This calls the code in Code Listing 2 (from event dg_ReportsList_SelectedIndexChanged)
to return the parameters.
Code Listing 2
Lancor.CrystalReportManager.CRParameterPanel
oPanelClass = new Lancor.CrystalReportManager.CRParameterPanel();
oPanelClass.ReportName=@"C:\Dev\DNNCrystal\DesktopModules\CrystalReportManager\ReportLibrary\ListHits.rpt";
oPanelClass.CreateParamsPanel();
ReportPanel.Controls.Add(oPanelClass);
As stated earlier, CRParameterPanel gets instantiated as
oPanelClass. Later, this Panel control gets added to ReportPanel. This panel
control is a container on the user control specifically for displaying the
parameters.
The method CreateparamsPanel adds the appropriate controls
to the panel for user entry. This method is based on some code from a previous
article, “Automagically
Display Crystal Parameters.” This method assumes that a parameter has
Prompting text that is used as a label on the web page.
This method first checks the Crystal SummaryInfo.Title
Property from the Crystal ReportDocument object, and adds that as the title of
the report. We use a label and that label control gets added to the Panel
object (oPanelClass). Once we add the title, then we iterate through the
ParameterFields collection in the ReportDocument.DataDefinition. The object
oReport in our code is the instantiation of the ReportDocument. See Code
Listing 3 for a snippet of the code.
Code Listing 3
oReport.Load(_reportName);
crTitle = oReport.SummaryInfo.ReportTitle;
System.Web.UI.WebControls.Label headingLabel = new
System.Web.UI.WebControls.Label();
headingLabel.Text=crTitle;
this.Controls.Add(headingLabel);
foreach (CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition
oCRParam in oReport.DataDefinition.ParameterFields)
{
System.Web.UI.WebControls.Label lblNew = new
System.Web.UI.WebControls.Label();
lblNew.ID="lbl" +
oCRParam.ParameterFieldName.Trim() + System.Convert.ToString(controlNum).Trim();
lblNew.Text=oCRParam.PromptText;
We create a label control with the Prompt from the
parameter. Then in further code, we determine the data type of the parameter.
Depending on the data type, we then use custom methods to create a server
control which is added to the Panel control after the label.
Once all the parameters have been iterated through, we will
set the View report buttons visible property to true. This button contains a
click event to display the report in the panel. We will cover that part of the
application in Part 4, the final part of this series.