How to set subReport reportsource dynamically

3 posts, 1 answers
  1. Mary
    Mary avatar
    10 posts
    Member since:
    Aug 2014

    Posted 08 Jun Link to this post

    I have a main report having subreport whose reportsource has to be set dynamically based on the field value (Response type) of the sqldatasource of mainreport ,
    I tried to get the value of Responsetype from the dataobject in detail_itemdatabinding event and stored in a variable .
    I subreport_itendataBinding event tried to set Telerik.Reporting.SubReport.reportsource to new object of TypeReportSource class, then invalidcastexception is ocurring
    Unable to cast object of type 'Telerik.Reporting.Processing.SubReport' to type 'Telerik.Reporting.SubReport
    'Telerik.Reporting.Processing.SubReport does not have REportsource property so i used Telerik.Reporting.SubReport, but exception is happening

    Kindly assist on this issue

     public partial class InterviewReport : Telerik.Reporting.Report
        {
            protected string reportSourceValue = "";
            public InterviewReport()
            {
                //
                // Required for telerik Reporting designer support
                //
                InitializeComponent();

                //
                // TODO: Add any constructor code after InitializeComponent call
                //
            }

            private void detail_ItemDataBinding(object sender, System.EventArgs e)
            {
                Telerik.Reporting.Processing.DetailSection item =
                    (Telerik.Reporting.Processing.DetailSection)sender;
             
                object o = item.DataObject["ResponseType"];
                if (o is string)
                {
                    if (string.Equals(o, "Text Response"))
                    {
                        this.reportSourceValue = "ReportLibrary.Reports.Response, ReportLibrary, Version=1.0.0.0, Culture=neutral, " +
         "PublicKeyToken=null";
                    }
                    else if (string.Equals(o, "Check Box"))
                    {
                        this.reportSourceValue = "ReportLibrary.Reports.ReportCheckBox, ReportLibrary, Version=1.0.0.0, Culture=neutral, " +
          "PublicKeyToken=null";
                    }
                }
            }

            private void subReport1_ItemDataBound(object sender, System.EventArgs e)
            {
                // Telerik.Reporting.Processing.ReportItemBase item =
                // (Telerik.Reporting.Processing.ReportItemBase)sender;
                Telerik.Reporting.SubReport sub = (Telerik.Reporting.SubReport)sender;

                Telerik.Reporting.TypeReportSource typeReportSource2 = new Telerik.Reporting.TypeReportSource();
                typeReportSource2.Parameters.Add(new Telerik.Reporting.Parameter("LocalEngID", "= Parameters.LocalEngID.Value"));
                typeReportSource2.Parameters.Add(new Telerik.Reporting.Parameter("InterviewQuestionsID", "=Fields.InterviewQuestionsID"));
                typeReportSource2.TypeName = reportSourceValue;
                sub.ReportSource = typeReportSource2;
            }

        }

     

    Regards,

    Mary Jain

  2. Answer
    Stef
    Admin
    Stef avatar
    3036 posts

    Posted 10 Jun Link to this post

    Hello Mary,

    In the SubReport item's event you will get Telerik.Reporting.Processing.SubReport element as sender. From the processing element you can access the ItemDefinition (Telerik.Reporting.SubReport).
    For more details, please check Understanding Events.

    The case can be handled without events and code. If you need to set the sub report depending on a field of the main report, you can add a SubReport Item and configure its ReportSource via binding and a custom function. The settings are illustrated in the attached demo project.

    I hope this information is helpful.

    Regards,
    Stef
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Mary
    Mary avatar
    10 posts
    Member since:
    Aug 2014

    Posted 10 Jun in reply to Stef Link to this post

    Thanks, i used Binding with InstanceReportSource.The example given is more easy.

    thanks one again

Back to Top