Refresh report when variable values are changed

Stimulsoft Reports.WEB discussion
Post Reply
Scottioioio
Posts: 47
Joined: Thu Dec 20, 2012 6:58 pm

Refresh report when variable values are changed

Post by Scottioioio »

I am displaying a report in an ASP.NET page using the StiWebViewer control. The report uses a Data Source that contains variables in the WHERE clause like so:

Code: Select all

SELECT ...
FROM MyTable
WHERE {condition}
In my ASP.NET page that loads the report I set the variable's value like so:

Code: Select all

StiReport report = new StiReport();
report.Load("...mrt");

report.Dictionary.Variables["condition"] = string.Format("Foo < {0} AND Bar >= {1}", txtFooValue.Text, txtBarValue.Text);

reportViewer.Report = report;
Where txtFooValue and txtBarValue are TextBox controls with numeric values.

The report correctly shows the subset of data based on the initial values in those TextBoxes, but when the user changes one of the values in these textboxes and clicks a Refresh button, I'd like to update the report so that it queries based on the new values. I am having no luck accomplishing this, however. I have the above code running on every visit to the page and I can step through the code using the Debugger and see that the variable is being assigned the new values in txtFooValue and txtBarValue. But the report that is displayed on the page shows the data with the initial values and is not filtering by the new values. And if I run SQL Server Profiler I see that no query is being sent to the database when the user clicks the Refresh button, even though the above code is running.

Is there some line of code I need to tell the report or StiWebViewer control to refresh?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Refresh report when variable values are changed

Post by HighAley »

Hello.

Do you use the OnGetReportData event handler of the StiWebViewer?
You should use it to set Data for report.

Thank you.
Scottioioio
Posts: 47
Joined: Thu Dec 20, 2012 6:58 pm

Re: Refresh report when variable values are changed

Post by Scottioioio »

No, my ASP.NET code-behind class does not use viewer's OnGetReportData event handler.

I'm not clear why I need to use that, though. I don't see any examples that use the GetReportData event and the only reference I see in the documentation is a short blurb in Stimulsoft_Reports_Manual.En.pdf that says:
Data are needed for rendering a report. By default, the data are taken which the specified in the Dictionary of the the report. If you want to override the data, you should subscribe to the GetReportData event. Here is an example of a code used to override data
I don't want different data for the report, I want the same data defined in the dictionary, just with updated parameter values.

Are you saying that to refresh the parameter values used to retrieve the data I need to use the GetReportData event? If so, could you provide an example that shows how this would be done?

Thanks
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Refresh report when variable values are changed

Post by HighAley »

Hello.

We have analysed your problem once more.
In this case you don't need to use GetReportData event.
Could you try to set the variable value with next code:

Code: Select all

report.Dictionary.Variables["condition"].Value = string.Format("Foo < {0} AND Bar >= {1}", txtFooValue.Text, txtBarValue.Text);
Did you get any error?

Thank you.
Scottioioio
Posts: 47
Joined: Thu Dec 20, 2012 6:58 pm

Re: Refresh report when variable values are changed

Post by Scottioioio »

I tried the above, no dice. I've also tried:

Code: Select all

report.Dictionary.Variables.Add("condition", string.Format("Foo < {0} AND Bar >= {1}", txtFooValue.Text, txtBarValue.Text));
May I suggest that you create a working example on your own end? This will let you better see the problem and come up with a solution.

Thanks
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Refresh report when variable values are changed

Post by HighAley »

Hello.

We'll try, but we need your report template with data for it.

Thank you.
Notrica

Re: Refresh report when variable values are changed

Post by Notrica »

Hello,

Unfortunately, I have the same problem as said above. But in spite the fact that i can see the query in SQL profiler correctly.
I used these statements to force the StiWebViewer to refresh, but the problem still exists.
They are :
report.Dictionary.DataStore.Clear();
report.Dictionary.Databases.Clear();
report.Dictionary.DataSources.Clear();
report.BusinessObjectsStore.Clear();

report.Dictionary.Synchronize();
report.Render();
And This is the whole code :

Code: Select all

            StiReport report = StiWebReport1.GetReport();
            report.Compile();
            report.Dictionary.Databases.Add(
                new StiSQLiteDatabase("Connection", ConnectionString));
            report.CompiledReport.DataSources["DataSource1"].Parameters["@RoomId"].ParameterValue = 
                int.Parse(ConferenceNo.Text.Trim().ToString());

            report.Dictionary.DataStore.Clear();
            report.Dictionary.Databases.Clear();
            report.Dictionary.DataSources.Clear();
            report.BusinessObjectsStore.Clear();

            report.Dictionary.Synchronize();
            report.Render();
            StiWebViewer1.Report = report;
Thank you so much.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Refresh report when variable values are changed

Post by HighAley »

Hello.

Please, add call ResetReport() method before setting the report in Page_Load event.

StiWebViewer1.ResetReport();
StiWebViewer1.Report = report;

Thank you.
Post Reply