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

Dynamic Report Viewing

1 Answer 194 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Danielle Ferguson
Top achievements
Rank 1
Danielle Ferguson asked on 11 Sep 2007, 01:10 PM
I am working on a dynamic feature where a report is loaded in a reportviewer.  I have a dropdownlist where the user can select one of the reports.  The selected report is then loaded in the viewer.

Each value in the dropdownlist called ddl1 is the name of the reporting class that I want to view.  For example, a user selects "InvoiceReport"...I would like the following to happen.

ReportViewer1.Report = new InvoiceReport();

I am unable to accomplish this because this is the code I have.

string strddl = ddl1.SelectedItem.Value + "()";
ReportViewer1.Report = new strddl;

Or I have been trying to do this as well...

Telerik.Reporting.Report report = (Telerik.Reporting.Report)ddl1.SelectedItem.Value;

How do I pass in the string value of the report name into the reportviewer1.report loading declaration?

Have any ideas?
Thanks

1 Answer, 1 is accepted

Sort by
0
Svetoslav
Telerik team
answered on 11 Sep 2007, 03:54 PM
Hello Tom,

It is not clear what programming language you're using but the easiest way to create an object from a string with .NET is to use reflection. Have in mind that you have to use the assembly qualified type name. Here is a code snippet in C# that demonstrates this technique:

string typeName = "MyNamespace.MyReport";     // replace this with your specific report type assembly qualified name
Type reportType = Type.GetType(typeName);
MyReport report = (MyReport)Activator.CreateInstance(reportType);


In case you want to learn more about the Activator.CreateInstance() you can start reading from here.
 

Best wishes,
Svetoslav
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Danielle Ferguson
Top achievements
Rank 1
Answers by
Svetoslav
Telerik team
Share this question
or