Solved

Setting Parameter value to droplist selected item

Posted on 2004-10-03
9
222 Views
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,
James
0
Comment
Question by:jhredd
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 12213709
Look at this
http://support.businessobjects.com/communityCS/FilesAndUpdates/aspxmps10.exe.asp

You want to look at the SimpleParameterFields example.

mlmcc
0
 

Author Comment

by:jhredd
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,

James
0
 
LVL 10

Expert Comment

by:ebolek
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

Regards
Emre

http://www.experts-exchange.com/Databases/Crystal_Reports/Q_21129085.html
0
 
LVL 3

Expert Comment

by:skpatra
ID: 12216771
Ok,
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();
oDoc.Load("C:\\MyDir\\Myreport.rpt");
//Assign parameters, ParameterName here is the name of your parameter in the report.
ParameterFieldDefinition oDefn = oDoc.DataDefinition.ParameterFields["ParamName"];
oDefn.CurrentValues.Clear();
ParameterValues colVals = new ParameterValues();
ParameterDiscreteValue oVal = new ParameterDiscreteValue();
oVal = new ParameterDiscreteValue();
oVal.Value = "something"; //Add your value here
colVals.Add(oVal);
oDefn.ApplyCurrentValues(colVals);
ctlReport.ReportSource = oDoc;
ctlReport.ShowFirstPage();


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

http://support.businessobjects.com/communityCS/TechnicalPapers/cr_net_sdk_additional_en.zip.asp
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:jhredd
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,
James
0
 
LVL 3

Accepted Solution

by:
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
0
 
LVL 10

Expert Comment

by:ebolek
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
0
 
LVL 3

Expert Comment

by:skpatra
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.
0
 

Author Comment

by:jhredd
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!

James
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now