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

NeedDataSource not fired for second time after update to Q3 2010

7 Answers 262 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sylvia
Top achievements
Rank 2
Sylvia asked on 15 Nov 2010, 04:16 PM
Hi,

in Q2 2010 Telerik Reporting I set the DataSource of a Report to null in the constructor and created dynamically sized textfields dynamically, dependent on some ReportParameter sent by a Silverlight Application via the Telerik WCF Service, in the overridden OnNeedDataSource method.. This worked like a charm.

In Q3 2010 Telerik Reporting the constructor of the Report also gets called twice like before. Once while requesting the report initially to be previewed in the Silverlight Report Viewer, the second time if exporting the Report to PDF or any other format from the Menu of the Silverlight Report Viewer. The first time the constructor is called, OnNeedDataSource gets called correctly and the dynamic Textfields get created, the second time the constructor is called (before saving to file), OnNeedDataSource does not get called, even though the DataSource is again set to null in the constructor.

In Short: Preview shows correct Report like in Q2. Saving to PDF (or any other format) produces blank file in Q3. In Q2 the Report was being saved correctly.

Since this is a time-critical issue, I am temporarily stepping back to Q2 2010 as of now. I hope this issue can be resolved.

Some code reconstructed to visualize what I wrote in the upper paragraphs:

Constructor:

/// <summary>
        ///   Initializes a new instance of the <see cref = "OverviewReportBase{T}" /> class.
        /// </summary>
        public OverviewReportBase()
        {
            //
            // Required for telerik Reporting designer support
            //
            InitializeComponent();
 
            // Set DataSource to null, so that the NeedDataSource Event gets fired.
            // This is done because otherwise the ReportParameters are not getting filled from the Silverlight Client.
            DataSource = null;
        }
OnNeedDataSource method:
/// <summary>
        ///   Called when the report needs a data source.
        /// </summary>
        /// <param name = "sender">The sender.</param>
        /// <param name = "e">The <see cref = "System.EventArgs" /> instance containing the event data.</param>
        protected override void OnNeedDataSource(Object sender, EventArgs e)
        {
            Unit writeableArea = CalculateWidthOfWriteableArea();
            IEnumerable<String> columnNames = ((Object[]) ReportParameters["columnNames"].Value).OfType<String>();
            Int32 columnCount = columnNames.Count();
            IEnumerable<Int32> columnPercentages =
                ((Object[]) ReportParameters["columnPercentages"].Value).Select(x => Int32.Parse(x.ToString()));
            Double summedUpWidth = 0D;
            for (Int32 i = 0; i < columnCount; i++)
            {
                Unit controlWidth = writeableArea.Multiply(columnPercentages.ElementAt(i)).Divide(100);
                TextBox captionTextBox = new TextBox
                                             {
                                                 Location =
                                                     new PointU(new Unit(summedUpWidth, UnitType.Mm),
                                                                new Unit(0, UnitType.Cm)),
                                                 Size = new SizeU(controlWidth, new Unit(0.75, UnitType.Cm)),
                                                 Name =
                                                     String.Format(CultureInfo.InvariantCulture, "captionTextBox{0}", i),
                                                 StyleName = "Caption",
                                                 TextWrap = false,
                                                 Value = RetrieveDisplayName(columnNames.ElementAt(i))
                                             };
                labelsGroupHeader.Items.Add(captionTextBox);
                TextBox dataTextBox = new TextBox
                                          {
                                              Location =
                                                  new PointU(new Unit(summedUpWidth, UnitType.Mm),
                                                             new Unit(0, UnitType.Cm)),
                                              Size = new SizeU(controlWidth, new Unit(0.75, UnitType.Cm)),
                                              Name = String.Format(CultureInfo.InvariantCulture, "dataTextBox{0}", i),
                                              StyleName = "Data",
                                              TextWrap = false,
                                              Value = RetrieveValuePathOfColumn(columnNames.ElementAt(i))
                                          };
                detail.Items.Add(dataTextBox);
                summedUpWidth += controlWidth.Value;
            }
            SetDataSourceHere();
            base.OnNeedDataSource(sender, e);
        }
Best Regards

7 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 18 Nov 2010, 05:20 PM
Hi Sylvia,

This behavior is by design. In the Q3 release we introduced data caching along the Drilldown Report Action functionality, from which benefits the overall performance since we would pull your data only once and this way the print and export would be much faster. We have not made this matter public, since it is only available for internal purposes and currently it cannot be controlled by users.
Anyway to get your scenario working again, simply change the event - instead of NeedDataSource, use ItemDataBinding, which would be fired always independent of whether there is data source or not.

Kind regards,
Steve
the Telerik team
See What's New in Telerik Reporting in Q3 2010 on Wednesday, November 17, 11am Eastern Time: Register here>>
0
Sylvia
Top achievements
Rank 2
answered on 30 Nov 2010, 12:27 PM
Hi Steve,

I finally had time to see if your suggestion concerning the ItemDataBinding event is working for us and wanted to thank you, because it does. Now our application can use the Q3 2010 release in the upcoming release.

Thank you for your support.
0
Tomas
Top achievements
Rank 1
answered on 02 Dec 2010, 07:13 PM
Hi Steve,

I have problem with the NeedDataSource as well but I'm not sure how related they are.

I have a table in my reportfooter region with no datasource specified because the data to retrieve and display in the table is dependent upon data from other regions of the report.
So I've set the datasource to none and added an event handler for the NeedDatasource like so:

private void table2_NeedDataSource(object sender, EventArgs e)
{
    var tmp = sender as Telerik.Reporting.Processing.Table;
    if (tmp != null)
    {
        Telerik.Reporting.Processing.TextBox customerIDTextBox =
            (Telerik.Reporting.Processing.TextBox)tmp.Report.ChildElements.Find("customerIDDataTextBox", true)[0];
        this.sqlDataSource2.Parameters.Add(new SqlDataSourceParameter("@customerID", System.Data.DbType.Int32, partnerValueTextBox.Text));
        tmp.DataSource = this.sqlDataSource2;
    }
}

This code runs fine and the customerID is found but when I view/preview the report I get an error in the area where the table should have been rendered.
Prior to 2010 Q3 this worked fine. As per your suggestion in this thread I changed to use the ItemDataBinding event instead and my report was back to normal. But as I see it I could actually benefit from the new data caching logic as my report doesn't really need the "second" call to NeedDataSource, right? But like I said currently it doesn't work at all.

I'm currently using the internal build version 4.2.10.1119 as it fixed another problem I was having with the official 2010 Q3 release.

Any suggestions?

EDIT: I actually do not get an error but the table includes no data,  just the tableheader is displayed.

Tomas
0
Steve
Telerik team
answered on 03 Dec 2010, 06:27 PM
Hi Tomas,

Looking at your code, we see no reason why you would work with the SqlDataSource Component (which is meant for design time experience) in event. Where is the dependency you talk about in this code? The NeedDataSource should be used for specifying data source to the respective Data Item and nothing else. You could take advantage of the caching by using design time binding through the data source component as well. Please use the data source component to bind the table from the designer and let us know if further help is needed.

Best wishes,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Tomas
Top achievements
Rank 1
answered on 06 Dec 2010, 05:44 PM

Hi Steve,

I'm not sure I understand your answer. First why wouldn't I use the SqlDataSource Component? Why should it be used only for design time experience?
Now back to my problem. I have another SqlDataSource Component (sqlDataSource1) that fetches the data from the database for the rest of the report but in order to fetch data for the table I first need to know the Customers ID and that's why I've set the tables datasource to null in order to get the NeedDataSource event to fire (but of course my problem is that this ain't working anymore in 2010 Q3). Here I then find the Customer's ID from a TextBox and add it as a parameter to my second SqlDataSource Component (sqlDataSource2). I think this approach is inline with your examples and demos. If it's possible to set the CustomerID parameter in the designer I would be more than happy to do it but I don't understand how I would accomplish that.

Tomas

0
Steve
Telerik team
answered on 09 Dec 2010, 03:05 PM
Hi Tomas,

The solution is to create a database inquiry for the SqlDataSource Component that you use as data source for the table item that exposes a parameter which take the value for the customerID. The dependency on database field from the main report is created with the following expression:

=ReportItem.DataObject.CustomerID

The ReportItem keyword is evaluated at runtime to the Data Item in which context the data source is used i.e. in our case Table item. The DataObject keyword specifies the data context in which the current data item is executed (in this case the Invoice report) and with the CustomerID we specify the field from that data context.
In other words, this expression helps us accomplish what the Parameters property serves for the subreport item.
If CustomerID comes from user input, simply set the Value for the data source parameter to a new Report Parameter where the user would input that data.

Greetings,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Tomas
Top achievements
Rank 1
answered on 13 Dec 2010, 01:37 PM

Hi Steve,

Thank you I wasn't aware of the ReportItem.DataObject syntax. This made my solution even cleaner.
Still something has changed in Q3 which broke my inital solution but for now your solution fills my needs.

Thanks

Tomas

Tags
General Discussions
Asked by
Sylvia
Top achievements
Rank 2
Answers by
Steve
Telerik team
Sylvia
Top achievements
Rank 2
Tomas
Top achievements
Rank 1
Share this question
or