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

Refreshing parameter with Web Viewer

8 Answers 271 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
dsavillian
Top achievements
Rank 1
dsavillian asked on 25 Mar 2009, 11:08 PM
Greetings,

I seem to be having a problem when using the web based Report Viewer when I set the report parameters at run time.


Here's a summary of the problem:

I have a report that is generating a data source in the NeedDataSource event. 
The data source is being generated using data from the ReportParameters collection.

I have an aspx page that has a viewer control that is not bound to a report at design time.
My report page has a series of input controls that can be used to change the report parameters. 
After the user enters his report parameters and clicks the submit button, the code behind creates a new report object, assigns the parameters and then assigns the report to the viewer control.

This works fine the first time the user generates the report.  If the user changes his parameters and regenerates the report, the report is always generated using the first set of parameters. 

Here is some of the sample code:

GenerateReport(p1,p2) is called when the user clicks a "submit" button.  I've simplified the parameters for ease of reading. 
ToplineMaster and VerbatimMaster are the report objects.  Based on the input from the user, we determine which report to show (but this only happens on the first load of the page, the user does not change report types on the fly)
private void GenerateReport(List<int> p1, List<int> p2)  
{  
  if(Mode == 1)  
  {  
    ToplineMaster report = new ToplineMaster();  
    report.ReportParameters["p1"].Value = p1;  
    report.ReportParameters["p2"].Value = p2;  
              
    rv_Rpt_Viewer.Report = report;  
  }  
  else if (Mode == 2)  
  {  
    VerbatimMaster report = new VerbatimMaster();  
    report.ReportParameters["p1"].Value = p1;  
    report.ReportParameters["p2"].Value = p2;  
              
    rv_Rpt_Viewer.Report = report;
  }  

Both report types use a similar NeedDataSource method.  I changed it a bit to keep things simple, but basically I'm generating report line items based on data generated from my business logic layer and then binding those line items to the report.  The report works fine when I run it the first time.
private void ToplineMaster_NeedDataSource(object sender, EventArgs e)     
        {     
            // given the question ids, load the questions from the database     
            // and bind the list to the report     
            List<int> p1 = new List<int>();     
            p1 = (List<int>)(sender as Telerik.Reporting.Processing.Report).Parameters["p1"];     
   
            List<int> p2 = new List<int>();     
            p2 = (List<int>)(sender as Telerik.Reporting.Processing.Report).Parameters["p2"];     
    
            List<BusinessDataObject> lineItems = new List<BusinessDataObject>();  
   
            foreach (int id in p1)     
            {    
                // generate data from business objects/database  
                lineItems.Add(Data);   
            }     
    
            (sender as Telerik.Reporting.Processing.Report).DataSource = lineItems;     
                 
    
        }    
 

I did some searching around today, but couldn't find the magic google/forum search query to find an explanation which leads me to believe that I'm doing something wrong.

Can anyone offer a hand?

Thanks!

8 Answers, 1 is accepted

Sort by
0
Accepted
Chavdar
Telerik team
answered on 26 Mar 2009, 01:47 PM
Hi dsavillian,

The correct behavior will be restored if you set the EnableViewState property of the report viewer to false. This is an issue with the viewer which will be fixed for the upcoming service pack in a few weeks.

We are sorry for the inconvenience.

Sincerely yours,
Chavdar
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
dsavillian
Top achievements
Rank 1
answered on 26 Mar 2009, 03:06 PM
Unfortunate that it's a bug, but glad that it's easy to get around!

Thanks!
0
Pete Haberstroh
Top achievements
Rank 1
answered on 17 Apr 2009, 06:38 PM
dsavillian,

the example of code that you provided it what I am trying to create, I am very new to telerik controls. I had a question, is your ToplineMaster_NeedDataSource your report class, that is recieving the two parameters to buid the list in that class ?

how did you set up your parameters on the report class side ?

Pete
0
Rick
Top achievements
Rank 2
answered on 02 Nov 2009, 03:51 AM
I am using the latest version of Telerik Reporting (Q2 2009) and I seem to have this same issue. I have set the EnableViewState property to False, but it is not fixing the problem.

I have created a new report with some report parameters. I am setting the datasource property of the report in the NeedDataSource event handler. As I said, I have set the EnableViewState property of the viewer in my website to False.

The event handler for NeedDataSource fires when the user clicks the Preview button. But the event does not fire again if the user changes the parameters and clicks the Preview button again.

I understand that I could change my query to ignore the report parameters and return all values that could possibly be needed regardless of what parameter values the user enters. Then I could generated the desired reports by using a filter filtering out the data that I don't want on the report. The problem with this approach is that the query may need to bring in a huge amount of data that may never be needed. This will create a performance problem for some of my customers. I would much prefer to requery the database each time the user clicks on the Preview button and only bring in the data that is actually needed.

Is there a way to do this?

Rick.
0
Steve
Telerik team
answered on 02 Nov 2009, 01:52 PM
Hi Rick,

Do you set the DataSource to the processing report object as shown in our help article? If you set it to the definition report object, this would explain why the event is not fired anymore. You can find more info on processing vs. definition items in this help article: Understanding Events.

Sincerely yours,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
cwk
Top achievements
Rank 2
answered on 03 Nov 2009, 09:40 AM
0
Steve
Telerik team
answered on 03 Nov 2009, 10:31 AM
Hi cwk,

The link is now fixed, the thing I was referring to is you should use

(sender as Telerik.Reporting.Processing.Report).DataSource = dataSet;

instead of

this.DataSource = dataSet;

All the best,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Rick
Top achievements
Rank 2
answered on 07 Nov 2009, 04:30 AM
Steve,

    Thanks. Those references were what I was looking for. If I hook the OnDataBinding event and use the sender parameter, I can accomplish what I need to do.

    Rick.
Tags
General Discussions
Asked by
dsavillian
Top achievements
Rank 1
Answers by
Chavdar
Telerik team
dsavillian
Top achievements
Rank 1
Pete Haberstroh
Top achievements
Rank 1
Rick
Top achievements
Rank 2
Steve
Telerik team
cwk
Top achievements
Rank 2
Share this question
or