How do I get a trdx report to display in a reportviewer in

2 posts, 0 answers
  1. Steve
    Steve avatar
    84 posts
    Member since:
    Aug 2013

    Posted 18 Jan 2014 Link to this post

    I must be dense or something, but for the life of me, can't figure out how to get a report viewer control to display a report.
    I need to dynamically set the report location and SQL server connection string in the code behind. The reason for this is,
    I want to call the report viewer from multiple areas in my application and populate it with different reports. Also, the
    SQL connection string resides in the web.config and is encrypted. I need to decrypt the string before passing it on to the
    report to use. Some reports are single layer and others have sub-reports in them.

    So, how do I do this in the code behind of a web form? Source code example would greatly be appreciated.

  2. Stef
    Stef avatar
    2926 posts

    Posted 21 Jan 2014 Link to this post

    Hi Steve,

    One approach is to create your own data access layer, where connection strings are decrypted and used to retrieve data based on permissions and other custom requirements. This layer with custom object can be used in report via ObjectDataSource/EntityDataSource/OpenAccessDataSource component. With this approach you can save further modifications on reports.

    The other approach is to work with the selected report instance and its Items collection. Each  item can be accessed from the report instance and modified e.g:
    Dim report As New MyReport()
    DirectCast(report.DataSource, Telerik.Reporting.SqlDataSource).ConnectionString = NewString()
    'get inner data item to change its data source as well
    DirectCast(report.Items.Find("Table1", True)(0), Telerik.Reporting.Table).DataSource = GetNewData()
    'get sub report
    Dim subreport = DirectCast(myReport.Items.Find("subReport1", True)(0), SubReport)
    'check the report definition to determine what is the used report source type for the SubReport item
    Dim instanceRS = DirectCast(subreport.ReportSource, InstanceReportSource)
    Dim subreportReport = DirectCast(instanceRS.ReportDocument, Report)
    subreportReport.DataSource = GetData()

    I hope this information helps you.


    New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.

  3. DevCraft banner
Back to Top