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

Table data binding problem in NeedDataSource

1 Answer 203 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
VH
Top achievements
Rank 1
VH asked on 10 Jan 2011, 05:15 AM
Hi,

I am using Telerik Report Q3 2010 SP1 (4.2.10.1221).
I created a master report and would like to add several sub-reports to it at run time with different data sources.

With the follow code, it generates what I want: (see attached image: expected.png)
public MasterReport()
{
      InitializeComponent();
      AddSubreports(111);
}

private void AddSubreports(int headerId)
{
        ReportDataSource c = new ReportDataSource(headerId);
        dss = c.GetSources();
        foreach (ParameterValuesReportDataSource ds in dss)
        {
            IndividualParameterReport subreport = new IndividualParameterReport(ds);
            SubReport subReport = new SubReport();
            subReport.Size = new SizeU(Telerik.Reporting.Drawing.Unit.Cm(8), Telerik.Reporting.Drawing.Unit.Cm(1));
            subReport.Dock = DockStyle.Top;
            subReport.ReportSource = subreport;
            detail.Items.Insert(0, subReport);
        }
}

However, I need to get the headerId first before I can call AddSubRepots method, so I modified the code to such:
public MasterReport()
{
InitializeComponent();
DataSource = null;
NeedDataSource += new EventHandler(MasterReport_NeedDataSource);
}
 
void MasterReport_NeedDataSource(object sender, EventArgs e)
{
headerId = Int32.Parse(ReportParameters["ParameterHeaderId"].Value.ToString());
AddSubreports(headerId);
}
Please see attached image: wrong.png 

The first two tables should contain 2 rows and the third one should contain 5 rows, but it only shows 2 in this case.
If I modified the order of my data source, show "Material" first, all tables display 5 rows.
Can someone help with explaining what's happening here?

Thanks,

VH

1 Answer, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 13 Jan 2011, 07:10 PM
Hi VH,

We have noticed in the code you have provided that you had used the Definition item of the Report Parameters instead of the Processing one. The definition Report Parameter's is actually the report parameter's default value. Additionally you should use the ItemDataBinding event instead. The NeedDataSource event should be used ONLY for providing data source to the report and nothing else.
private void MasterReport_ItemDataBinding(object sender, EventArgs e)
{
    int headerId = Int32.Parse((sender as Telerik.Reporting.Processing.Report).Parameters["ParameterHeaderId"].Value.ToString());
    AddSubreports(headerId);
}

Additionally the Location property is mandatory for the report items. If Location property is omitted the report items will overlap and this may cause unexpected results.

A similar issue slipped into the Q3 2010 release and has been fixed immediately, thus please upgrade to the official release Q3 2010 Service Pack 1.

Kind regards,
Peter
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
Tags
General Discussions
Asked by
VH
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or