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

Using Table.DataObject property to access object being bound

1 Answer 300 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 08 May 2009, 06:00 PM
I have a report that is bound to a list of objects representing a tract of land. Each tract object has a property that is a list of owners for that tract. I am using the new Table control introduced in Q1 2009 to list the owners of the tract without having to use a subreport. 

The Table is in the detail section and I am programatically binding the owners for each tract by handling the ItemDataBinding event of the detail section using the following code:

Telerik.Reporting.Processing.ReportItemBase section = (Telerik.Reporting.Processing.ReportItemBase)sender;
Telerik.Reporting.Processing.Table table = (Telerik.Reporting.Processing.Table)section.ChildElements["tblOwners"];
table.DataSource = section.DataObject["Owners"];

In this case the DataObject is equal to the Tract object currently being bound, as expected, and I'm accessing the Owners property which is the list of tract owners.

This all works fine, however, I now have the need to access a property of the Owner object that is currently being bound. I am using a similar technique to the one I used for the detail section by handling the ItemDataBinding event of the table with the following code:

Telerik.Reporting.Processing.Table table = (Telerik.Reporting.Processing.Table)sender;
Owner tractowner = (Owner)table.DataObject.RawData;

I would expect the DataObject to be for an Owner object, however, at runtime the report throws an exception indicating that it is not possible to cast a Tract object to an object of type Owner. For some reason the table.DataObject is not for an Owner object, but instead for a Tract object even though the table is bound to a list of Owners.  

This does not make sense to me. Is this a bug, or am I misunderstanding the use of the DataObject property and if so, how do I access the Owner object that is currently being bound?

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 11 May 2009, 02:07 PM
Hi David,

We can only guess what is going on without a sample report, however we have a similar implementation in our ProductCatalog sample report. Open the VS examples, select the table item and check out the filters we have set on it.

If still having problems, please send us a sample runnable project and we would be able to advise you accordingly.

Best wishes,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or