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

Load Report from list in database table

1 Answer 85 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Doug Hamilton
Top achievements
Rank 1
Doug Hamilton asked on 08 Oct 2010, 03:22 PM
I have a website that I am developing.  The site consists of 20 reports.  The list of reports available to the user would be filtered by the users security level.  I have the report names and descriptions set in an SQL Table on the server.  

I have a reportviewer.aspx page where I would like to pass the name of the report to be viewed to the viewer based on the report selected from a radgrid.  The reports themselves are created in a "reportlibrary" project in the same VS solution.  I know I can hard code the code behind to select the correct report but I don't want to recode the page everytime a new report is created.  Is there an easy way to set the report property on the reportviewer object to the name of the report:

This what I have:

Dim report1 As New ReportLibrary.rptDelinquent(parid, userid, ordnum, ordname)
Dim report2 As New ReportLibrary.rptTaxBill(parid, userid, ordnum, ordname)
If Not String.IsNullOrEmpty(oProduct.PrdReportName) Then
    Select Case UCase(Trim(oProduct.PrdReportName))
        Case "RPTDELINQUENT"
            Me.eTaxiReportViewer.Report = report1
        Case "RPTTAXBILL"
            Me.eTaxiReportViewer.Report = report2
    End Select
  
    Me.Page.Title = "eTaxi Report Viewer - " + oProduct.PrdDescription
End If


This is what I would like to do:

If Not String.IsNullOrEmpty(oProduct.PrdReportName) Then
Dim report1 As New ReportLibrary(oProduct.PrdReportName)(parid, userid, ordnum, ordname)

    
' oproduct.prdReportname would be "rptDelinquent"
    Me.eTaxiReportViewer.Report = report1 
    Me.Page.Title = "eTaxi Report Viewer - " + oProduct.PrdDescription
End If

Doug

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 12 Oct 2010, 04:46 PM
Hello Doug Hamilton,

In order to create instance from the report name our suggestion is to use the Activator.CreateInstance method that create an instance from the AssemblyQualifiedName of the type using the constructor that best matches the specified parameters.
Check out the following code snippet for an example:

string reportName = @"Telerik.Reporting.Examples.CSharp.Invoice, WindowsFormsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
Type reportType = Type.GetType(reportName);
IReportDocument report = (IReportDocument)Activator.CreateInstance(reportType);
this.reportViewer1.Report = report;
 
You can see this approach in action in our Visual Studio examples. The Report Catalog finds and displays all reports in the class library automatically.

Best wishes,
Peter
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Doug Hamilton
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or