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

Issues with NeedDataSource firing on Report Sub Table

1 Answer 169 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
SemiPro
Top achievements
Rank 1
SemiPro asked on 01 Aug 2014, 10:35 PM
So I'm new to Telerik, and have been struggling getting a NeedDataSource event to fire in an ASP .NET web application with the latest version of Reporting, Q2 2014 (8.1.14.618).  Interestingly, the code I'm about to post works fine in the much older version (3.1.9.701) and I'm at a loss as to what has changed and why the code that used to work is broken now.  

So in our aspx page we have a simple ReportViewer Control

<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" style="margin: 0px;">
    <form id="form1" runat="server">
        <div style="height: 100%;">
            <telerik:ReportViewer ID="ReportViewer1" runat="server" width="100%" height="100%">
            </telerik:ReportViewer>
        </div>
    </form>
</body>


The code behind file goes and gets data when the page loads:
01.protected void Page_Load(object sender, EventArgs e)
02.{
03.    if (!IsPostBack)
04.    {
05.        LoadData();
06.    }
07.}
08. 
09.private void LoadData()
10.{
11.    Page.Title = "Report Title";
12. 
13.    ReportBook reportBook = new ReportBook();
14. 
15.    CustomReport1 report = new CustomReport1();
16.    CustomReport2 report2 = new CustomReport2();
17.    CustomReportData data = new CustomReportData(_Id);
18.    report.DataSource = data;
19.    report2.DataSource = data;
20. 
21.    reportBook.Reports.Add(report);
22.    reportBook.Reports.Add(report2);
23. 
24.    this.ReportViewer1.Report = reportBook;
25.}


And then the code generated from the designer looks like this, CustomReport1.cs:
01.public partial class CustomReport : Telerik.Reporting.Report
02.{
03.    public CustomReport()
04.    {
05.        /// <summary>
06.        /// Required for telerik Reporting designer support
07.        /// </summary>
08.        InitializeComponent();
09. 
10.        //create event that will set the data source for the table
11.        tbl.NeedDataSource += new EventHandler(tbl_NeedDataSource);
12.    }
13. 
14.    /// <summary>
15.    /// Handles the NeedDataSource event of the tbl control.
16.    /// </summary>
17.    /// <param name="sender">The source of the event.</param>
18.    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
19.    void tbl_NeedDataSource(object sender, EventArgs e)
20.    {
21.        //In order to programmatically set the table, we need to use the processing table
22.        Telerik.Reporting.Processing.Table table = ((Telerik.Reporting.Processing.Table)sender);
23. 
24.        //set the data source of the table
25.        table.DataSource = ((CustomReportData)table.Report.DataSource).CustomCollection;
26.    }
27.

For line 25, CustomCollection is just a list of BLL objects.  The craziest thing for me is that when I run with the old version I can hit breakpoints inside tbl_NeedDataSource function.  However, with the new Telerik controls I am unable to hit anything in the tbl_NeedDataSource function.  I'm wondering what may have gotten lost in translation to the newer controls, maybe there's some kind of mechanism that became obsolete between those two versions that would cause the "wiring" not to work.  Or maybe there's just a better way to do this now :)  Any thoughts or suggestions would be helpful.  Thanks in advance!

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 06 Aug 2014, 03:07 PM
Hi,

The NeedDataSource event would fire only if the data item's DataSource property is not set. Also if the web application is running in out-proc session state mode, you must subscribe for the event in the report's ItemDataBinding event. All rules required for running in out-rpoc are listed in the Design Considerations for Out-proc Session State help article.

An approach we recommend instead of using events is described in the How to Databind to Collection Properties KB article. Using expressions you can avoid the settings required for out-proc session state mode.
Other approach is to directly access the Table item from the report instance's Items collection and set its DataSource e.g.
var report =new Report1();
var table = report.Items.Find("table1", true)[0] as Telerik.Reporting.Table;
table.DataSource = GetData();
 
myReportBook.Reports.Add(report);


I hope the above information helps you.

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
SemiPro
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or