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

dynamically handling report classes in the report viewer

1 Answer 49 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Axel
Top achievements
Rank 2
Axel asked on 02 Oct 2009, 01:03 AM

Hi,

I have created a UserControl (ascx) with the Report Viewer. I am creating instances of my report classes dynamically. My Report viewer code looks like this:

            if (!Page.IsPostBack)  
            {  
                if (!string.IsNullOrEmpty(_reportName))  
                {  
                    PageManagementDataContext db = new PageManagementDataContext();  
 
                    var rec = db.ReportGetByReportIDAndLCID(Convert.ToInt32(_reportName), "is-IS").FirstOrDefault();  
 
                    if (rec != null)  
                    {  
                          
                        Object obj = Activator.CreateInstance(Type.GetType("Orbit.Benjamin.Reports." + rec.systemname));  
 
                        Telerik.Reporting.Report rpt = (Telerik.Reporting.Report)obj;  
 
                          
                        ReportViewer1.Report = rpt;  
                        ReportViewer1.ZoomMode = Telerik.ReportViewer.WebForms.ZoomMode.Percent;  
                        ReportViewer1.ZoomPercent = 100;  
                        ReportViewer1.Style["height"] = "30cm";  
                    }  
                }  
            }  
 
        }  
 
        protected object GetNewType(string classname)  
        {  
            Type type = Type.GetType(classname, true);  
            object newInstance = Activator.CreateInstance(type);  
            return newInstance;  
        } 

Everyting was working fine until I tried to add parameters to a report. I'm adding a parameter using this code:
var enterpr = db.EnterprisesAndDivisionsGetAll().Where(d => d.partyroleid != 4);  
 
var parameter = this.ReportParameters["Company"];  
parameter.UI.AvailableValues.DataSource = enterpr.Select(o => o.partyname);  
parameter.Value = enterpr.Select(o => o.id); 

This causes my class instance to fail. I suspect I need to do something to also handle the parameters when creating the class instance. Can someone point me in the right direction please.

reg.
Axel

1 Answer, 1 is accepted

Sort by
0
Axel
Top achievements
Rank 2
answered on 02 Oct 2009, 11:28 AM
IGNORE....

Class instancing was OK. Error in linq syntax caused theproblem... :-(
Tags
General Discussions
Asked by
Axel
Top achievements
Rank 2
Answers by
Axel
Top achievements
Rank 2
Share this question
or