dynamically handling report classes in the report viewer

2 posts, 0 answers
  1. Axel
    Axel avatar
    41 posts
    Member since:
    Jul 2009

    Posted 01 Oct 2009 Link to this post

    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

  2. Axel
    Axel avatar
    41 posts
    Member since:
    Jul 2009

    Posted 02 Oct 2009 Link to this post

    IGNORE....

    Class instancing was OK. Error in linq syntax caused theproblem... :-(
  3. DevCraft banner
Back to Top