Setting Parameter value to droplist selected item

Posted on 2004-10-03
Last Modified: 2008-01-09
Hi, I'm using C# and Visual 2003. I have crystal Reports 10 and My project is an ASP. I have a droplist which is filled from a dataset. This works fine but I want to be able to select a value from the droplist and set the parameter and then call my report. Maybe using a button to call the report. I have The Complete Reference on Crystal Reports 10 and can't find an example on how to do this anywhere.  I have a paramater defined for the report named p_name. I have set the table field of LastName equal to p_name in the select expert in the report. If I run the report it promts me for the parameter. The value type for the db field and parameter is a string. When I enter the parameter  value for the prompt the report is called and the data is filtered correctly.

I just want to be able to do this from my droplist which is what the end user needs to be able to do. I'm new to .net and CrystalReports so could you please include any name spaces I would need in your example. I have been searching endlessly for  a way to do this. Please help me. If you could explain it that would be great but if you know of a specific example to go along with it that would be awesome.

Many Thanks,
Question by:jhredd
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
LVL 101

Expert Comment

ID: 12213709
Look at this

You want to look at the SimpleParameterFields example.


Author Comment

ID: 12216664
Hi, thank you for the reply but as I said I'm new to .net and crystal reports. I'm a little confused because when I create a new project of ASP Web type there is a webform created for me. It has the extension of .aspx
On that form is where I want to be able to put my controls for the droplist,etc. I downloaded the samples you suggested but they are all of asp type. There is not project form for me to work from. All there is, is a lot of html/asp code that I don't understand. Is there no way for me to get an example of what I need that has a webform to look at.

If I'm not making myself clear pleas let me know. Sometimes what I think and write are not the same.

Thanks So much for the help,

LVL 10

Expert Comment

ID: 12216723
Check out the code thta I wrote in this link. It is C# and it works. I am using it in my application

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button


Expert Comment

ID: 12216771
I assume that
1. There is a drop down to select the parameter value
2. There is a button to generate the report

My solution below assumes that you want to see the report in a crystal report viewer.
Now, follow these steps

1. Add a CrystalReportViewer server control in your webform. You can locate this control in the toolbox in the VS.Net. Drag drop this on your web page. Name the control as ctlReport.
2. Add references to namespase CrystalDecisions.Shared and CrystalDecisions.CrystalReports.Engine in your code behind. You will now write teh report generation code in the button onclick event handler in the code behind.
3. Ad the following code to the button click event handler.

ReportDocument oDoc = new ReportDocument();
//Assign parameters, ParameterName here is the name of your parameter in the report.
ParameterFieldDefinition oDefn = oDoc.DataDefinition.ParameterFields["ParamName"];
ParameterValues colVals = new ParameterValues();
ParameterDiscreteValue oVal = new ParameterDiscreteValue();
oVal = new ParameterDiscreteValue();
oVal.Value = "something"; //Add your value here
ctlReport.ReportSource = oDoc;

Now, if you need complete reference, you can download helpfiles from the following location. This gives examples under many scenarios:

Author Comment

ID: 12216895
skpatra, I have just one question for you:
oVal.Value = "something"; //Add your value here

What should I put here. The data type as in string, etc or the name of my parameter field or the name in my database table where the parameter is goint to get it's data from?

I'm a little confused on this part.

Thank You,

Accepted Solution

skpatra earned 500 total points
ID: 12216954
Sorry for not making it clear. "Something" represents the value you want to set for the parameter. In your case it will be the selected value in your DropDownList. (you can use cmbValues.SelectedValue, where cmbValue is the id of the DropDownList being used). Note that the Value property of ParameterDiscreteValue is an Object and hence you can ad any data type (string/int/short etc) you want. So the code should look like

oVal.Value = cmbValues.SelectedValue

instead of

oVal.Value = "something"; //Add your value here
LVL 10

Expert Comment

ID: 12216955
The example that skpatra gave is the viewer object model though. Viewer object model is limited an dwhen you use it, you cant chnage to anothe robject model. So if you have more runtime customizations to be done, this is not the good way to go

Expert Comment

ID: 12217023
Hi ebolek,
I am not suggesting/using the viewer object model. If you look at my code snippet all my manipulation is being done using the Report Document Object Model. I am just using the viewer to view the report. You may as well just export it to pdf in which case you will not need the viewer at all.
Viewer object model is all about loading an rpt file to the viewer directly (without using the ReportDocument model) and I agree that it gives you limited option to manipulate the reports.
But this is a different topic all together and you can find a detailed discussion of this in the link i mentioned in my first response.

Author Comment

ID: 12244895
Hello Everyone, I just wanted to take the time to say thank you for taking the time to help me with this problem.

I really appreciate it!


Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question