Automagically Display Crystal Parameters: Part I
page 1 of 1
Published: 07 May 2004
Unedited - Community Contributed
This article is a walkthrough of a sample application that programmatically displays crystal reports parameters on a web page and outputs that same report.
by Eric Landes
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 12597/ 18

[Download Sample App]
This series of articles will walk through a sample application that loads a Crystal Report and displays the parameters the report needs programmatically.  When the user enters the parameter information, the application then calls and displays the report. 


I intend for this sample application to be extendable.  Think of building your own database of reports and allowing users to select the reports to display, or some other permutation I haven't thought of.


I’ve separated this series of articles in three installments.  First, we’ll go through the initial display of the parameters on the web page.  Next, we’ll go through the class that actually determines the parameters and how to display them on the page.  And finally, we’ll log onto the report and display the report as a PDF.


These articles assume familiarity with ASP.NET and Crystal Reports .NET.  For more information on Crystal Reports with .NET, be sure to visit the Crystal Alliance site at  The downloadable sample application is written in VB.NET. 


Getting the Parameters from the Report

The following information is based on the sample application I’ve included with this series of articles.  The sample solution application includes a web project and a class project written in VB.NET.  Let me briefly tell you about the class file.  I’ll cover parts of it in depth in the second installment of this article.

   View of Visual Studio Project

The class PCRMCreateCRObjects will create a collection that contains the objects to place on the page.  The main parts of this class are the controlsCollection collection and the GetBuilder method.  controlsCollection contains the web form controls that are added to the user input page.


I start out with a page, _displayCR.aspx that contains the controls for user input.  This page on initial examination only contains a Panel control.  The code-behind for this page will add controls for parameter input based on the report that is used.  The page in the sample application is a bit bland, and begs for you to add some style to it; however, it does give you a great idea of the nuts and bolts necessary to programmatically set up your parameter input controls. 


View of web page _displayCR.aspx

In page_load, the CreatePage method is called.  CreatePage instantiates a new PCRMCreateCRObjects class to create the parameter controls.  A report name can be passed (I’ve used a querystring that includes a file identifier), but for the purposes of this sample, the report name is hard coded. 


Depending on the type of parameters, CreatePage will put the correct server controls in the panel.  For instance, if a parameter is a boolean type, a CheckBox server control will be placed in the panel.  The GetBuilder method determines the correct server control.


The object oCrystalEntry is an instance of a custom class PCRMCreateCRObjects.  This custom class does the work of finding the parameters that this Crystal Report may have.  The method we use is called GetBuilder.  This method is described later in the article.


Public Sub CreatePage()

        Dim oCrystalEntry As New PCRMCreateCRObjects()

        Dim oEntry As Object


        ' Get the filename and location from the PCRMFile object

          & "\customerOrders.rpt")


The GetBuilder method builds all the parameter information into the instantiated object.  This includes the header information, which is added to the Panel object on the page first.  Once that is added, other style HTML can be added to the panel.  In the sample app, a break is added. 


Now we begin iterating through the parameters that the report has, using the collection controlsCollection. 

For Each oEntry In oCrystalEntry.controlsCollection

    ' This assumes that labels for the control are

    ' placed after the control

    If UCase(oEntry.GetType.FullName) <> UCase(labelName) Then

      Dim _literalBr As New System.Web.UI.LiteralControl()

      _literalBr.Text = "<br>" = oEntry.ParamID & "1"

      PlaceLabel(oCrystalEntry.controlsCollection, oEntry.LabelID)



      _literalBr.ID = "literal" & Trim(oEntry.labelid)


      _literalBr = Nothing

    End If



This part of the method adds the control that was determined by the GetBuilder method for this parameter into the page.  It also adds a label and an ID.  I use a naming scheme for the ID consistently by adding the paramid + 1 to the control's ID in the collection.  This naming scheme could be improved--I may be improving this later--but it works for now. 


_literalBr is a LiteralControl to add the HTML tag <br> to the panel.  Once all objects are iterated through, a submit button and a hidden form element are added to the panel.  The hidden form element is not necessary in the sample app, but when you are passing file names via a querystring or other method, it allows you to make this application flexible for many reports.


In Part II, we'll go over the class that builds the parameters. 

More Crystal Resources

Crystal Alliance

User Comments

Title: Postback problem   
Name: Kapil
Date: 2005-03-03 11:04:13 AM
Hi Eric,
I have downloaded your sample application for Crystal report with Parameter and it works great.However when I introduce the If not Postback in the Page load event in the _displayCr.aspx.vb ,it does not work. Would be greatful
if you can guide why it does not work... I have been stuck on these issue for last two days....


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
End If
Title: This project   
Name: Don
Date: 2005-01-23 12:48:34 PM
Let me give something back, (I was coming back here to do just that). In actuality. I believe you Mr. Landes are a genius just for your work here. There is no doubt in anyone's mind that this works, if all the developer's planets are lined up. The comment code comes out quite easily. The report can be redone in the version of crystal the user has. The database can be changed to access or whatever the user has. Dot net then goes into some type of circular error conditions, you fix one and another comes around. It is like the wagons have been put in a circle but the indians will not stop attacking. Me thinks this battle can be fought, but never won! On my machine that is! lol Did I give you a chuckle. I hope so. Thank you for your wonderful code. I am going to take it up to the mountain and see if I can be given some divine inspiration as to how it works. Kudos to you.
Title: In answer to Don   
Name: Eric Landes
Date: 2005-01-22 9:04:50 PM
I appreciate your comments. The VB Comments DLL should not need a license, since it was free, but that was a while ago. And I should have mentioned the Crystal 10 thing as well. But please keep in mind that this is not a production strength application, but more of a proof of concept. The code download is there to show you how I'm automatically displaying parameters, and applying them using Crystal. If I have time, I'll try to clean the comment generator stuff out of this.
Title: DOA   
Name: Don
Date: 2005-01-22 7:45:50 PM
There are several surprising issues with this project:
1. The reference to your internal VB commenter dll must be deleted, (unless the user has a license like Mr. Kimbrough I guess has.).
2. Delete the reference to the other application. Compile that one on your machine and then recompile this one. It will compile.
3. You better have SQL server on your machine because the crystal report uses Northwind from SQL server (someone forgot to mention that eh?)
4. You will also need Crystal Reports V10 on your machine since the report was written in that.
5. After that you will only have the errors 'Specified cast is not valid', and 'Unable to validate data' to contend with. I haven't debugged those yet.

I think some editor has not done their job here. Is this Microsoft or what?!!!
5. I think this project was only written for Mr. Kimbrough and Mr. Landes. lol
Title: No problem getting system to work   
Name: Bob Kimbrough
Date: 2004-10-11 12:55:06 PM
I had no problem getting this sample to work.

I downloaded the sample onto my WinXP/VS .NET 2003/CR 10 machine and copied the CrystalParams folder to inetput/wwwroot. Next, I opened the CrystalParams project with VS .NET 2003 and yes, there was a bad reference to a third party control. I simply deleted the reference and then readded it. Viola! Success!

This something that every VS .NET developer should be able to do.
Title: Could not compile   
Name: Sam
Date: 2004-09-09 1:00:10 PM
Title: Really poor   
Name: bob
Date: 2004-08-17 7:12:24 AM
This is really poor not to have a working download. No one can get it to work dude. This is really unfortunate because the idea is really a good. If you fix it up I'm sure you will get better comments.
Title: Problem Using this Sample   
Name: Ppero
Date: 2004-08-09 12:11:48 PM
Hi, I'm trying to use the sample but it has several dll missing, please upload the complete project (including complementary dll). I'd like add that the coding is for VS 2003, so 2002 users must make some changes before use.

Please HELP

Title: Those not having this work.   
Name: Eric Landes
Date: 2004-07-29 11:05:54 PM
Folks, I have downloaded and tested this, and have not had problems. Check back in a week for an update and if I can duplicate the error I'll get it fixed.
Title: Automagically Display Crystal Parameters: Part I   
Name: michael watkins
Date: 2004-07-29 10:56:43 PM
sample app didn't work for me either. managed to clear all the reference errors but kept getting errors at runtime. no description for setting up the sample makes this pretty lame imho.
Title: Did not work for me using C#   
Name: Acyl
Date: 2004-07-13 4:20:15 PM
I tried it, but I did not have luck with it using C#.
I have a web Application that diplay a crsytal Report (VS.NET 2003) and I want to use Parameters on my Crsytal Report
Thanks a billion + tax
Please Help!
Title: Class not able to find:clsFileProjLink   
Name: Abhijit Roy
Date: 2004-07-03 6:50:21 AM
I tried to configure the project to make it work, somehow i am not able to get clsFileProjLink class in declaration and not able to execute the project.

Please help !!!!


Product Spotlight
Product Spotlight 

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

©Copyright 1998-2024  |  Page Processed at 2024-07-15 4:56:26 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search