I need to know when to pass parameters to a subreport

6 posts, 0 answers
  1. Ryan Emptage
    Ryan Emptage avatar
    28 posts
    Member since:
    Feb 2009

    Posted 05 Feb 2009 Link to this post

    Hi

    I have a main report which uses an xml file (to DataTable) as a datasource containing Member ID's.
    I also have a subreport for the Member's Addresses.

    As each Member is processed in the main report I want to pass the MemberID to the subreport, where I then pass the MemberID into as a parameter in DataAdapter.Fill() method.

    I have already implemented the passing of parameters into the DataAdapter and also implemented properties in the subreport to store the parameters being passed from the main report. As so:

     public partial class PersonalSubReport : Telerik.Reporting.Report 
        { 
            private int _paramOid; 
            private int _paramMemberId; 
     
            public PersonalSubReport() 
            { 
                /// <summary> 
                /// Required for telerik Reporting designer support 
                /// </summary> 
                InitializeComponent(); 
     
                // TODO: This line of code loads data into the 'dsMemberPersonalDetails.dsMemberPersonalDetailsTable' table. You can move, or remove it, as needed. 
                try 
                { 
                    this.dsMemberPersonalDetailsTableAdapter1.Fill((this.dsMemberPersonalDetails.dsMemberPersonalDetailsTable), _paramOid, _paramMemberId); 
                } 
                catch (System.Exception ex) 
                { 
                    // An error has occurred while filling the data set. Please check the exception for more information. 
                    System.Diagnostics.Debug.WriteLine(ex.Message); 
                } 
            } 
     
            public int ParamOid 
            { 
                get 
                { 
                    return _paramOid; 
                } 
                set 
                { 
                    _paramOid = value; 
                } 
            } 
     
            public int ParamMemberId 
            { 
                get 
                { 
                    return _paramMemberId; 
                } 
                set 
                { 
                    _paramMemberId = value; 
                } 
            } 

    My question is....when do I set the properties?
    I tried setting them in the main report sections item databinding event but this occurs after the subreport's DataAdapter.Fill() method is called so parameters being passed are 0 and no data is being returned in the subreport.

    Many thanks.




  2. Chris Gillies
    Chris Gillies avatar
    384 posts
    Member since:
    May 2006

    Posted 05 Feb 2009 Link to this post

    Take a look at this video: http://tv.telerik.com/reporting/video/Telerik_Reporting_-_Design_Time_Support_for_Parameterized_Queries and you might want to review Reporting Parameters and Reporting Item Data Binding videos as well.

    Cheers
  3. DevCraft banner
  4. Ryan Emptage
    Ryan Emptage avatar
    28 posts
    Member since:
    Feb 2009

    Posted 05 Feb 2009 Link to this post

    I've already used those videos before hand.

    And they are fine if the parameter value is specified pre-runtime, i.e. in a textbox.
    However, the parameter value I am trying to pass is specified during runtime because its coming from the datasource of the main report.

    I guess that by design, the data for the datasource in the subreport is loaded BEFORE the detail_ItemDataBinding event of the main report is fired.

    What I might try instead is to create the subreport control and report object manually. That way I have more control and I can pass the parameters just before.

     

  5. Ryan Emptage
    Ryan Emptage avatar
    28 posts
    Member since:
    Feb 2009

    Posted 05 Feb 2009 Link to this post

    Can anyone from Telerik help with this?
    We are still trialling this product and the outcome of this will make or break our decision to purchase.
    Thanks.
  6. Michael
    Michael avatar
    19 posts
    Member since:
    Oct 2008

    Posted 05 Feb 2009 Link to this post

    This is what worked for me...

    In the Main Report (MainReport.cs) add this:

    private void subReport1_ItemDataBinding(object sender, System.EventArgs e) 
            { 
                Telerik.Reporting.Processing.ReportItemBase item = sender as Telerik.Reporting.Processing.ReportItemBase; 
                if (null != item) 
                { 
                    DataRowView dataRow = (DataRowView)item.DataItem; 
                    this.SubReport.Param1 = (int)dataRow["Param1"]; 
                    this.SubReport.Param2 = (int)dataRow["Param2"]; 
                     
                } 
            } 

    In the code above "this.SubReport" is a reference to the Sub report's Report Source (SubReport.cs), not to the name of the subreport object as it is defines in the main report.  I hope that makes sense.

    In the MainReport.Designer.cs (in the forbidden don't overwrite section) add this:
    this.subReport1.ItemDataBinding += new System.EventHandler(this.subReport1_ItemDataBinding); 



  7. Michael
    Michael avatar
    19 posts
    Member since:
    Oct 2008

    Posted 05 Feb 2009 Link to this post

    Also, check this post:

    http://www.telerik.com/community/forums/reporting/telerik-reporting/set-subreport-datasource-programmatically.aspx#421286

    It helped me.



Back to Top
DevCraft banner