This is a migrated thread and some comments may be shown as answers.

Report parameters always using design time values

4 Answers 357 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 19 Apr 2013, 09:30 AM
Hi there,

I've created  a set of reports, most of which have a chart and a grid.
The reports pull data from a SQL data source, and pass in a StartDate and EndDate parameter.
I've set these up as Report Parameters, and these are visible when viewing the report as users will need to change date ranges.

The report parameters have a default value, i.e. I set the value in design time using a function. This sets StartDate to first day of the current month, and EndDate to last day of the current month.

However, when changing the values of these parameters on the report viewer, it seems to always use the design time set values, the value the user enters is never used.

Why is this? Should I be setting the default value in another manner?
I've tried setting 'Value' in the ReportParameter Collection Editor from design mode in VS2012, and I've tried setting it in the constructor of the report after InitializeComponent.

4 Answers, 1 is accepted

Sort by
0
Chavdar
Telerik team
answered on 23 Apr 2013, 01:02 PM
Hello,

If you are using the NeedDataSource event to set the data source then make sure that you are using the Parameters collection of the processing report rather than the ReportParameters collection from the report definition. Please, check the Using Report Parameters programmatically help article which demonstrates how to use the parameters correctly.

If this is not the case, please open a support ticket and send us a sample runnable project so that we can check the incorrect behavior at our side.

Regards,
Chavdar
the Telerik team

Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.

0
Stephen
Top achievements
Rank 1
answered on 23 Apr 2013, 01:59 PM
Hi Chavdar,

Thanks for the reply.

I'm not using the NeedDataSource event, and I'm not setting parameter values programmatically.
I just want to set the initial value via an expression in the designer.

To reproduce, I've created a new solution with a single report.
I'm only using the designer, have not written any code.
In this sample I'm not setting parameter values anywhere, so when the report loads, it prompts the user for StarDate and EndDate.

Just found something else which may be of value. The report parameters do actually update. The chart does actually seem to use the new values for the query, but not for the legend. I guess this is where the confusion is coming in.
I placed a textbox on the report with the expression "= Parameters.StartDate.Value". This changes after updating the parameter value, and clicking Preview. However the chart does not render the correct values.

See attached screenshots.
Screen 1 - Run the report, select StartDate as 2013-01-01, EndDate as 2013-04-30. Expect to see chart with Jan, Feb, Mar and Apr data.

Screen 2 - Update the report parameters to have StartDate as 2013-04-01, EndDate as 2013-04-30 and click Preview. Expect to see only data for Apr.

The data I'm using in this example is very basic. The data looks like:

ID          Date                    Day         Total
----------- ----------------------- ----------- -----------
2           2013-01-01 00:00:00.000 1           43
3           2013-01-02 00:00:00.000 2           14
4           2013-01-03 00:00:00.000 3           42
5           2013-01-04 00:00:00.000 4           98
6           2013-01-05 00:00:00.000 5           60
7           2013-01-06 00:00:00.000 6           78
8           2013-01-07 00:00:00.000 7           93
9           2013-01-08 00:00:00.000 8           2
10          2013-01-09 00:00:00.000 9           29
11          2013-01-10 00:00:00.000 10          77
12          2013-01-11 00:00:00.000 11          84



The query for the report is:
SELECT
    DateName(m, [Date]),
    [Day],
    SUM(Total) [Total]
FROM Test
WHERE [Date] BETWEEN @StartDate AND @EndDate
GROUP BY [Date], [Day]


Would you like me to submit a support request with the full solution?

Thanks,
Stephen
0
Accepted
Chavdar
Telerik team
answered on 29 Apr 2013, 08:57 AM
Hello,

A possible solution for this problem is to clear the chart's series collection on the ItemDataBinding event of the report. Here is a sample code snippet that illustrates the approach:

public Report1()
{
    InitializeComponent();
 
    this.ItemDataBinding += Report1_ItemDataBinding;
}
 
void Report1_ItemDataBinding(object sender, EventArgs e)
{
    var chart1 = (Telerik.Reporting.Chart)this.Items.Find(this.chart1.Name, true)[0];
    chart1.Series.Clear();          
}

Please, have in mind that the Chart item has been obsolete since the Q1 2013 release and is replaced by the more powerful Graph item. Our advice is to try to use the new item for making charts if possible.

Here are two more links for the Graph item that you might find helpful:

Kind regards,
Chavdar
the Telerik team

Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.

0
Stephen
Top achievements
Rank 1
answered on 29 Apr 2013, 10:05 AM
Hello Chavdar,

Thanks for the response.
I've put in the code on the ItemDataBinding event as you recommend and that does solve the issue, thank you!

I'm also taking a look at the new Graph control, looks like it will suit our needs better than the Chart.

Thanks for the assistance.

Regards,
Stephen
Tags
General Discussions
Asked by
Stephen
Top achievements
Rank 1
Answers by
Chavdar
Telerik team
Stephen
Top achievements
Rank 1
Share this question
or