Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Setting Parameter value to droplist selected item

Posted on 2004-10-03
Medium Priority
Last Modified: 2008-01-09
Hi, I'm using C# and Visual Studio.net 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


Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.


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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 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