Telerik Forums
Reporting Forum
4 answers
660 views
We have some very complex reports that must be fed by a data controller class library.   The Telerik ObjectDataSource the is used to represent controller methods as data sources in the designer assume that the data access methods are static.  Unfortunately, our controllers do not have parameter-less constructors.  It has become more challenging to cope with this limitation ever since the SubReport ReportSource could be something other than a Telerik Report.  I have struggled to find the best way to replace Telerik SubReport ObjectDataSources programmically in your TR Q1 2013 SP1 release.  I am hoping that someone who has a strong opinion will evaluate our approach because Google hasn't revealed a clear answer to us.

Facts and Assumptions About Telerik Reporting

Let's make sure that I have my facts straight:

  1. The recommended way to represent a controller method as a data source in the Telerik Reports designer is the ObjectDataSource. 
  2. The Telerik ObjectDataSource assumes that the controller method it calls is static.  
  3. The recommended way to override a data source programmatically is to bind to the SubReport's NeedDataSource event.
  4. A Report will only fire its NeedDataSource event if the Report's DataSource property is set to null.
  5. A Telerik SubReport acts like a placeholder control.  It could represent a Telerik Report or a blob of text.  This flexibility makes it impossible to directly access the DataSource of a Report that is instantiated by a SubReport at compile time.  Instead, you must programmatically instantiate the Report, change its properties and then replace the SubReport.ReportSource with the new Report instance.

All true?  If not, please explain.

Hypothetical Report

Now suppose we have a nested stack of Telerik Reports where Report1 includes SubReport2 to instantiate Report2 that in turn includes SubReport3 to instantiate Report3.  Report1 is instantiated by an ASP.NET page and bound to the Telerik ReportViewer.  Here's what we would do to replace the ObjectDataSource at run-time:

  1. When we instantiate Report1, we use a custom constructor that receives a LINQ to SQL data context as an argument.  Given a data context, we instantiate our controllers inside Report1.cs.  In the Report1 ItemDataBinding event handler, we replace SubReport2.ReportSource like so:
  2. public Report1(LINQToSQLDataContext dataContext)
    {
        //
        // Required for telerik Reporting designer support
        //
        InitializeComponent();
        // custom constructor actions
        this.DataContext = context;
      
        // for debugging
        detail.ItemDataBound += new EventHandler(detail_ItemDataBound);
        this.detail.ItemDataBinding += new EventHandler(detail_ItemDataBinding);
        // force NeedDataSource to fire
        this.DataSource = null;
        this.NeedDataSource += new EventHandler(Report1_NeedDataSource);
        this.Error += new ErrorEventHandler(Report1_Error);
      
        // replace the subReport in order to pass it the MyContactMethodController to replace its static DataSource
        Report2 emailReport = new Report2SubReport(this.MyContactMethodController);
        this.Report2SubReport.ReportSource = new InstanceReportSource() { ReportDocument = emailReport };
        this.Report2SubReport.ReportSource.Parameters.Add(new Telerik.Reporting.Parameter("parameter1", "=Fields.ID"));
        this.Report2SubReport.ReportSource.Parameters.Add(new Telerik.Reporting.Parameter("effectiveDate", "=Parameters.effectiveDate.Value"));
    }
      
    #region Event Handlers
      
    void Report1_NeedDataSource(object sender, EventArgs e)
    {
        Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
        var id = report.Parameters["ID"].Value;
        _ID = Convert.ToInt32(ufdID);
        var effectiveDT = report.Parameters["effectiveDate"].Value;
        _effectiveDate = Convert.ToDateTime(effectiveDT);
        this.DataSource = this.MyDataController.GetHighLevelInfo(_ID, _effectiveDate);
    }
      
    // for debugging
    void Report1_ItemDataBinding(object sender, EventArgs e)
    {
        int? id = (((Telerik.Reporting.Processing.ReportItemBase)(sender))).DataObject.RawData as int?;
    }
      
    // for debugging
    void detail_ItemDataBinding(object sender, EventArgs e)
    {
        Telerik.Reporting.Processing.ReportSection reportSection = sender as Telerik.Reporting.Processing.ReportSection;
        HighLevelInfo data = reportSection.DataObject.RawData as HighLevelInfo;
        _ID = data.ID;
    }
      
    // for debugging
    void detail_ItemDataBound(object sender, EventArgs e)
    {
        Telerik.Reporting.Processing.ReportSection reportSection = sender as Telerik.Reporting.Processing.ReportSection;
        var data = reportSection.DataObject.RawData;
    }
      
    void Report1_Error(object sender, ErrorEventArgs eventArgs)
    {
        throw new Exception(string.Format("{0} Telerik Report Exception:  {1}", this.Name, eventArgs.Exception.ToString()), eventArgs.Exception);
    }
    #endregion Event Handlers
2.  In Report2:
public Report2(DataController dc)
{
    //
    // Required for telerik Reporting designer support
    //
    InitializeComponent();
    //
    // TODO: Add any constructor code after InitializeComponent call
    //
    // save controller for the NeedDataSource event handler
    this.MyDataController = dc;
    // force NeedDataSource to fire
    this.DataSource = null;
    this.NeedDataSource += new EventHandler(Report2_NeedDataSource);
    this.Error += new ErrorEventHandler(Report2_Error);
  
    // replace the subReport in order to pass it the MyDataController
    Report3 report3 = new Report3(this.MyDataController);
    // force NeedDataSource to fire
    report3.DataSource = null;
    this.Report3SubReport.ReportSource = new InstanceReportSource() { ReportDocument = report3 };
    this.Report3SubReport.ReportSource.Parameters.Add(new Telerik.Reporting.Parameter("parameter1", "=Parameters.parameter1.Value"));
    this.Report3SubReport.ReportSource.Parameters.Add(new Telerik.Reporting.Parameter("parameter2", "=Parameters.effectiveDate.Value"));
    this.Report3SubReport.ReportSource.Parameters.Add(new Telerik.Reporting.Parameter("parameter3", "=Fields.ID"));
    this.Report3SubReport.ReportSource.Parameters.Add(new Telerik.Reporting.Parameter("parameter4", "=Fields.Name"));
}
  
private DataController MyDataController { get; set; }
  
private void Report2_NeedDataSource(object sender, EventArgs e)
{
    int parameter1 = Convert.ToInt32(this.ReportParameters["parameter1"].Value);
    DateTime effectiveDate = Convert.ToDateTime(this.ReportParameters["effectiveDate"].Value);
    List<DetailInfo> detailList = this.MyDataController.GetDetailInfoList(parameter1, effectiveDate);
    this.DataSource = detailList;
}
  
void Report2_Error(object sender, ErrorEventArgs eventArgs)
{
    throw new Exception(string.Format("{0} Telerik Report Exception:  {1}", this.Name, eventArgs.Exception.ToString()), eventArgs.Exception);
}


3.  In Report3:
public Report3(DataController dc)
{
    //
    // Required for telerik Reporting designer support
    //
    InitializeComponent();
    //
    // TODO: Add any constructor code after InitializeComponent call
    //
    // save controller for the NeedDataSource event handler
    this.MyDataController = dc;
    // force NeedDataSource to fire
    this.DataSource = null;
    this.NeedDataSource += new EventHandler(Report3SubReport_NeedDataSource);
    this.Error += new ErrorEventHandler(Report3SubReport_Error);
}
 
private DataController MyDataController { get; set; }
 
private void Report3SubReport_NeedDataSource(object sender, EventArgs e)
{
    int parameter1 = Convert.ToInt32(this.ReportParameters["applicantUserFormDetailID"].Value);
    DateTime effectiveDate = Convert.ToDateTime(this.ReportParameters["effectiveDate"].Value);
    int parameter3 = Convert.ToInt32(this.ReportParameters["skillCategoryID"].Value);
    List<MoreDetailInfo> moreDetailInfoList = this.MyDataController.GetMoreDetailInfo(parameter1, parameter2, effectiveDate);
    // bind datasource directly to my table.  Binding to this.DataSource leaves the table blank.
    this.MyTable.DataSource = moreDetailInfoList;
}
 
void Report3SubReport_Error(object sender, ErrorEventArgs eventArgs)
{
    throw new Exception(string.Format("{0} Telerik Report Exception:  {1}", this.Name, eventArgs.Exception.ToString()), eventArgs.Exception);
}


Is there a better way to implement this hypothetical report?
 


Jim
Top achievements
Rank 1
 answered on 02 Apr 2015
9 answers
400 views
I just started playing with Telerik Reporting. I'm hoping to migrate a simple single page report I currently do in .net using PDFGenerator.

With PDFGenerator you can embed javascript. In my case I add the following line:
MyDocument.JavaScripts.Add(New DocumentJavaScript("print", "this.print({bUI: false, bSilent: true, bShrinkToFit: true});"))

Which results in the PDF file going straight to the printer.

I created the following code in a new .aspx file using sample code I found in the docs.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
        Dim report As New Telerik.Reporting.Report() 
        Dim detail As New Telerik.Reporting.DetailSection() 
        Dim textBox2 As New Telerik.Reporting.TextBox() 
        textBox2.Location = New Telerik.Reporting.Drawing.PointU(New Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Inch), New Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Inch)) 
        textBox2.Value = "Hello World!" 
        textBox2.Location = New Telerik.Reporting.Drawing.PointU(New Telerik.Reporting.Drawing.Unit(1.25, Telerik.Reporting.Drawing.UnitType.Inch), New Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Inch)) 
        textBox2.Size = New Telerik.Reporting.Drawing.SizeU(New Telerik.Reporting.Drawing.Unit(4.75, Telerik.Reporting.Drawing.UnitType.Inch), New Telerik.Reporting.Drawing.Unit(0.25, Telerik.Reporting.Drawing.UnitType.Inch)) 
        detail.Items.AddRange(New Telerik.Reporting.ReportItemBase() {textBox2}) 
        detail.Height = New Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch) 
        report.Items.Add(DirectCast(detail, Telerik.Reporting.ReportItemBase)) 
        ExportToPDF("Test", report) 
    End Sub 
 
    Sub ExportToPDF(ByVal reportName As String, ByVal reportToExport As Telerik.Reporting.Report) 
        Dim mimeType As StringString = String.Empty 
        Dim ext As StringString = String.Empty 
        Dim encoding As EncodingEncoding = Encoding.[Default] 
        Dim reportBytes As Byte() = ReportProcessor.Render("PDF", reportToExport, Nothing, mimeType, ext, encoding) 
        Dim fileName As String = reportName + ".pdf" 
        Response.Clear() 
        Response.ContentType = mimeType 
        Response.Cache.SetCacheability(HttpCacheability.[Private]) 
        Response.Expires = -1 
        Response.Buffer = False 
        Response.AddHeader("Content-Disposition", String.Format("{0};FileName=""{1}""", "attachment", fileName)) 
        Response.OutputStream.Write(reportBytes, 0, reportBytes.Length) 
        Response.[End]() 
    End Sub 

This code generates a PDF directly just like my PDFGenerator code.

How do I embed javascript directly in the PDF generated by the Telerik Reporting control?



KS
Top achievements
Rank 1
 answered on 02 Apr 2015
3 answers
145 views
Hi,

I'm using the table item to display a simple table with columns A and B:

Column A     Column B
Value_A_1   Value_B_1
Value_A_1   Value_B_2
Value_A_1   Value_B_2
Value_A_2   Value_B_4
Value_A_2   Value_B_5
Value_A_2   Value_B_6

I'd like the report to look like this:
Value_A_1
     Value_B_1
     Value_B_2
     Value_B_3
Value_A_2
     Value_B_4
     Value_B_5
     Value_B_6

If I use a row group grouping by Column A the report looks like this:
Value_A_1  Value_B_1
                   Value_B_2
                   Value_B_3
Value_A_2  Value_B_4
                   Value_B_5
                   Value_B_6

If I use a column group grouping by Column A the report looks like this:
Value_A_1
     Value_B_1
     Value_B_2
     Value_B_3

<Pagebreak>
Value_A_2



     Value_B_4
     Value_B_5
     Value_B_6

Why it does a page break after each group and why it displays the emtpy lines in group Value_A_2?

Best regards,
Gerd
Hinata
Top achievements
Rank 1
 answered on 01 Apr 2015
1 answer
141 views
Hi

Previously I had this (The source of the report definition has not been specified) error when accessing the report on a page however recently I have had it when looking at the report preview.

Creating a blank test project all was OK on a basic report simply showing a barcode.  So I started to match it with my live site and on the second change managed to replicate the issue.  My live site is set to compile for x64.  The test site is set to AnyCpu, switching that to x64 caused the report preview to fail and display the "The source of the report definition has not been specified". Reverting to back AnyCPU and it worked.

I assume that this is a bug...

Regards

Jon
Stef
Telerik team
 answered on 01 Apr 2015
2 answers
77 views
So I have a specific image that will load into a picturebox when I run the reportviewer locally, but it doesn't work when it's deployed.

All the other images work fine, using the same loading method.  All other images of this category work for all other items.  It's just this one image, that only works locally, but not from the webserver.

The image is not displayed, but I am displaying some of it's attributes, and it's saying the image is a jpeg, that is 808x1049 pixels wide.

Anyone ever encounter an issue like this?

Thanks!
Stef
Telerik team
 answered on 01 Apr 2015
1 answer
126 views
I'm standing generate the report in PDF and e-mail, but when will render the following error appears:

Failure in transparent security method 'Telerik.Reporting.Pdf.Fonts.TrueType.FontReader.GetFontData(System.Drawing.Font, Boolean ByRef)'  when calling native code by the method 'Telerik.Reporting.Pdf.Native.NativeMethods.GetDC(IntPtr)'. Methods must be safety-critical or critical to safety and available in transparent code to call native code. I'm using Telerik Reporting Q1 2015 version.
Stef
Telerik team
 answered on 30 Mar 2015
2 answers
117 views
Hello there,

I'm evaluating Telerik Reporting and I'm struggling with something that I know how to do in SSRS but I have no idea how to achieve it here.

I'm using a line chart to show patient admissions trends for the last 6 months by payor type.

Issues:

1) I'm using Analysis Services as my data source, when I chose month as my category group, the months are sorted alphabetically. In SSRS I can reset the sort, and they will show in calendar order by default, but it seems that is not an option here. 
I tried providing a user function for both grouping and sorting; but it doesn't seem to work.

2) How can I handle empty values? I want empty values to be shown as "0". I found this http://www.telerik.com/help/reporting/featuresemptyvalues.html but I can't find where to set the EmptyValue properties nor how to get to the ChartSeriesCollection properties.

Thanks in advance!
R.
Hinata
Top achievements
Rank 1
 answered on 30 Mar 2015
1 answer
280 views
I am trying to convert report from Active Report to Mailing Label Report. I have done the steps in the post called "Converting reports from ActiveReports"
http://www.telerik.com/support/kb/reporting/details/converting-reports-from-activereports but I am not getting "Convert from existing report" after adding a report to my project.

The version of Reporting is Q1 2015.
Stef
Telerik team
 answered on 30 Mar 2015
1 answer
206 views
Can I embed the Query Designer from he Standalone designer in my own application? Is there a tutorial on how to do that?

Thanks!
Nasko
Telerik team
 answered on 27 Mar 2015
3 answers
224 views
Hi,
I'm developing reports on StandAlone Report designer. The report consists to get all users from DB and show them in a list. I read how to create custom functions in order to transform users images that is as string64 in DB to Image in PictureBox. In this case, it's work very well.
So, then i decided to test on my Silverlight application. Configure web.config on my project as well but it didn't work. I follow this example this example in this same report and it works fine but the images does not show.

What i'm doing wrong?
Stef
Telerik team
 answered on 27 Mar 2015
Top users last month
Edmond
Top achievements
Rank 1
Iron
fabrizio
Top achievements
Rank 2
Iron
Veteran
RobMarz
Top achievements
Rank 2
Iron
Fakhrul
Top achievements
Rank 1
Iron
Tejas
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?