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

I need to know when to pass parameters to a subreport

5 Answers 266 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ryan Emptage
Top achievements
Rank 1
Ryan Emptage asked on 05 Feb 2009, 11:35 AM
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.




5 Answers, 1 is accepted

Sort by
0
Chris Gillies
Top achievements
Rank 1
answered on 05 Feb 2009, 02:28 PM
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
0
Ryan Emptage
Top achievements
Rank 1
answered on 05 Feb 2009, 03:16 PM
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.

 

0
Ryan Emptage
Top achievements
Rank 1
answered on 05 Feb 2009, 04:47 PM
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.
0
Michael
Top achievements
Rank 2
answered on 05 Feb 2009, 07:17 PM
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); 



0
Michael
Top achievements
Rank 2
answered on 05 Feb 2009, 07:25 PM
Also, check this post:

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

It helped me.



Tags
General Discussions
Asked by
Ryan Emptage
Top achievements
Rank 1
Answers by
Chris Gillies
Top achievements
Rank 1
Ryan Emptage
Top achievements
Rank 1
Michael
Top achievements
Rank 2
Share this question
or