Click here to Skip to main content
15,879,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using crystal report viewer 13 in asp.net C# project to show crystal report viewer.

In the crystal report, a couple of static parameters are being used to populate values accordingly and to show subreports.

I am facing one issue is, when you refresh the report it prompts for parameter values and that can be changed based on the utilization of the same report.

So My question is, How I can populate that default values programmatically, so the user does not have to fill again those data on the parameter prompt on refresh of the report viewer?

What I have tried:

I have tried to set up these values during the design time of the crystal report, but as per my utilization of the report, it should be populated based on what screen users are. Like user can access the same report from 3 different screens with different parameter values like department.
Posted
Updated 25-Sep-20 2:35am

1 solution

Did you try something like:
C#
using CrystalDecisions.Shared;

...
private void ParamButton_Click(object sender, System.EventArgs e)
{

  // Create parameter objects
  ParameterFields myParams = new ParameterFields();
  ParameterField myParam = new ParameterField();
  ParameterDiscreteValue myDiscreteValue = new ParameterDiscreteValue();

  // Set the ParameterFieldName to the name of the parameter
  // created in the Field Explorer
  myParam.ParameterFieldName = "Country";
			
  // Add first country
  myDiscreteValue.Value = "USA";
  myParam.CurrentValues.Add(myDiscreteValue);
			
  // Reuse myDiscreteValue, and assign second country
  myDiscreteValue = new ParameterDiscreteValue();
  myDiscreteValue.Value = "Netherlands";
  myParam.CurrentValues.Add(myDiscreteValue);
				
  // Add param object to params collection
  myParams.Add(myParam);
		
  // Assign the params collection to the report viewer
  myCrystalReportViewer.ParameterFieldInfo = myParams;
		
  // Assign the Report to the report viewer.
  // This method uses a strongly typed report,
  // but other methods are possible as well.
  myCrystalReportViewer.ReportSource = MyReportObject;

}

Reference: Passing Multiple Parameters to a Crystal Report Programmatically[^]
 
Share this answer
 
Comments
Paresh_Kapuriya 25-Sep-20 9:05am    
Yes. I tried this, But whenever I refresh the report from the crystal report viewer panel, It does not show values on parameters on the prompt for a refresh.

Can't we use myParam.DefaultValues?
Sandeep Mewara 25-Sep-20 9:11am    
I believe it should have worked. When you try it does not?

Also, if there is countable param scenario, like 3 flows - have three paramters and make use of the needed one on refresh?
these params has static values in design.
Paresh_Kapuriya 25-Sep-20 9:20am    
I have tried your solution like it, Then I refreshed the report, it does not show me values in the param value textbox of the refresh prompt.

Totally there are four parameters, 2 of them are used for which company name and shift name, the rest of the 2 are used on a formula to show a message or a subreport accordingly.

All of them are static parameters which likely a report parameter. I am using the Page_PreInit method to populate the report. Apart from that, I am using the ADO.NET(XML) connection for the report.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900