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

Subreport in GroupFooter

4 Answers 187 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Koen L
Top achievements
Rank 1
Koen L asked on 15 Feb 2012, 04:10 PM
Hi,

I need to put a subreport in a groupfooter, and I can't seem to make it work.
So, I have a Master Report, called List, this object has several properties that have to be set on the Master report.
In the detailsection I've put an SubReport, this Detail Report contains all lines from the List.
Until here, everything works great.
In the detailreport I've added several groups, because the lines have to be grouped.

Example:

Driver A (Driver-Group)
    Customer X (Customer Group)
         Address XYZ (Address Group)
              - Line1
              - Line 2
              - Line 3
          Address XYZ Footer: SubReport with all carriers on line 1,2,3
        Address ABC
              - Line 4
              - Line 5
         Adress ABC Footer: Subreport with all carriers on line 4,5
    Customer Y
    ...
Driver B
...

So I've managed to display all lines corretly,
I've also managed to get all group-data (Driver A, Customer X, Address XYZ)
By storing it in private variable in the detail_ItemDataBound,
when I debug I see that the correct data is being fetched.

private void detail_ItemDataBound(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.DetailSection detailSection = (Telerik.Reporting.Processing.DetailSection)sender;
 
            TransportListDocument doc = (TransportListDocument)detailSection.DataObject.RawData;
 
            if (doc != null)
            {
                if( String.IsNullOrEmpty(doc.Memo))
                {
                    txtMemo.Visible = false;
                    captionMemo.Visible = false;
                }
 
                txtType.Value = Translator.Translate("_" + doc.DocumentType);
                listId = doc.TransportListId;
                driverId = doc.Driver.Id;
                customerId = doc.Customer.Id;
                addressId = doc.Address.Id;
            }
        }

private void subCarriers_NeedDataSource(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.SubReport subReport = (Telerik.Reporting.Processing.SubReport)sender;
            if(listId > 0 && driverId > 0 && customerId > 0 && addressId > 0)
            {
                AmountOfCarriers amountOfCarriers = DataFacade.Transport.DFCarrier.GetAmountOfCarriers(listId, driverId, CustomerId, addressId, LanguageId, BranchId);
 
                if (amountOfCarriers != null && amountOfCarriers.Count > 0)
                {
                    subTLCarriers1.SetPrivateDataMembers(Translator, LanguageId);
                    subTLCarriers1.DataSource = amountOfCarriers;
                }
            }
        }


or by using the data I find for each Address-group:

private void groupFooterAddress_ItemDataBound(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.ReportSection addressGroupSection = ((Telerik.Reporting.Processing.ReportSection)sender);
            Telerik.Reporting.Processing.Group customerGroup = ((Telerik.Reporting.Processing.Group)addressGroupSection.Parent.Parent);
            Telerik.Reporting.Processing.Group driverGroup = ((Telerik.Reporting.Processing.Group)customerGroup.Parent);
            TransportListDocuments docs = (TransportListDocuments)addressGroupSection.Report.DataSource;
 
 
            int selectedAddressId = ((Address)addressGroupSection.DataObject["Address"]).Id;
            int selectedCustomerId = ((ObjectModel.Customer.Customer)(customerGroup.GroupHeader.DataObject["Customer"])).Id;
            int selectedDriverId = ((Driver)(driverGroup.GroupHeader.DataObject["Driver"])).Id;
 
            AmountOfCarriers amountOfCarriers = DataFacade.Transport.DFCarrier.GetAmountOfCarriers(docs[0].TransportListId, selectedAddressId, selectedCustomerId, selectedDriverId, LanguageId, BranchId);
 
            if (amountOfCarriers != null && amountOfCarriers.Count > 0)
            {
                subTLCarriers1.SetPrivateDataMembers(Translator, LanguageId);
                subTLCarriers1.DataSource = amountOfCarriers;
 
            }
        }

which is sufficient to me to get data for the subreport in the footer.


Only the last line of code (subTLCarriers1.DataSource = amountOfCarriers;) sets the datasource on the control on the Detail Report, not the instance of the subreport in de groupFooter, as result, I get the same subreport for ALL the groups in my Detail Report instead of a different subreport for each address-group of lines.

Could you help me find a way to set the DataSource of each instance of the subreport in the Group-Footer,
so that each Address-Group get it's own subreport in it's footer?

Any help is very much welcome since I've been struggling with this for a few days now.



4 Answers, 1 is accepted

Sort by
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 16 Feb 2012, 09:14 AM
You don't need to catch events to do all that stuff.
You can either:
1. use bindigs http://www.telerik.com/help/reporting/expressions-bindings.html to assign the data-source for the SubReport
2. pass the parameters to the SubReport and let the SubReport get the data itself. For example you pass listId, driverId, CustomerId, addressId, LanguageId, BranchId as parameters to the SubReport and then in the subReport you assign the datasource 
DataFacade.Transport.DFCarrier.GetAmountOfCarriers(listId, driverId, CustomerId, addressId, LanguageId, BranchId); 
you should also use ObjectDataSource component instead of assigning the data-source in code. 

0
Koen L
Top achievements
Rank 1
answered on 16 Feb 2012, 03:07 PM
HI!

Thank you for your quick response!
But I'm still struggling with following:
(and the tutorial/knowledge base pages of Telerik are very summir and not very helpful for my use of Telerik Reporting)

1. Binding can't be used, since you can only select an expression or a field of the reports datasource.
    Or I don't understand how to use it.
2. I've managed to pass the values through ReportParameters like this:
private void groupFooterAddress_ItemDataBound(object sender, EventArgs e)
       {
           Telerik.Reporting.Processing.ReportSection addressGroupSection = ((Telerik.Reporting.Processing.ReportSection)sender);
           Telerik.Reporting.Processing.Group customerGroup = ((Telerik.Reporting.Processing.Group)addressGroupSection.Parent.Parent);
           Telerik.Reporting.Processing.Group driverGroup = ((Telerik.Reporting.Processing.Group)customerGroup.Parent);
           TransportListDocuments docs = (TransportListDocuments)addressGroupSection.Report.DataSource;
 
 
           int selectedAddressId = ((Address)addressGroupSection.DataObject["Address"]).Id;
           int selectedCustomerId = ((ObjectModel.Customer.Customer)(customerGroup.GroupHeader.DataObject["Customer"])).Id;
           int selectedDriverId = ((Driver)(driverGroup.GroupHeader.DataObject["Driver"])).Id;
 
           subTLCarriers1.ReportParameters["ListId"].Value = listId;
           subTLCarriers1.ReportParameters["DriverId"].Value = selectedDriverId;
           subTLCarriers1.ReportParameters["CustomerId"].Value = selectedCustomerId;
           subTLCarriers1.ReportParameters["AddressId"].Value = selectedAddressId;
       }

I putted the reportparameter in design to the value of datafield (DriverId = Field.Driver.Id) I got null's everywhere, so I had to put them in code. Also, don't forget the subreport is in the footer, so I have no Idea what Field.Driver.Id has for values since whe're in a groupfooter not in detail section.
This is in my Details-SubReport (lines-report, which contains the groupfooter with the subreport in it)

Now I get correct reportparameters in my GroupFooterSubreport but I don't know where to add this:

DataFacade.Transport.DFCarrier.GetAmountOfCarriers(listId, driverId, CustomerId, addressId, LanguageId, BranchId);
to assign it as datasource of the GroupFooterSubReport

If you could give me a little bit more info, as an example or something, that would be great.
I come from standard RDL and RDLC's in Visual Studio background and MS SQL Reporting Services,
the customer wants Telerik Reporting, which is not bad, but completely different in implementation.

Thank you in advance for your time


0
Accepted
Hadib Ahmabi
Top achievements
Rank 1
answered on 17 Feb 2012, 10:01 AM
Inside the Details-SubReport (the actual report, that serve as a sub-report), on Report_NeedDataSource event you can get the processing report and get the param values from there (not from the definition, but from the processing) and then simply call your method that retrieves the data
private void DetailsReport_NeedDataSource(object sender, EventArgs e)
{
    var report = (Telerik.Reporting.Processing.Report)sender;
    var listID = report.Parameters["listId"].Value;
    ...
      report.DataSource = DataFacade.Transport.DFCarrier.GetAmountOfCarriers(listId, driverId, CustomerId, addressId, LanguageId, BranchId);
}


0
Koen L
Top achievements
Rank 1
answered on 20 Feb 2012, 11:50 AM
This solution worked for me!
Thank you very much for your help!
Tags
General Discussions
Asked by
Koen L
Top achievements
Rank 1
Answers by
Hadib Ahmabi
Top achievements
Rank 1
Koen L
Top achievements
Rank 1
Share this question
or