How to reference DataTable column data in Report Item Expression?

1 Answer 26 Views
DataSources
Michael
Top achievements
Rank 1
Michael asked on 03 Nov 2023, 07:56 AM | edited on 03 Nov 2023, 04:48 PM

I'm trying to create a Report that has a dynamically generated DataTable as its DataSource.

I’ve programmatically placed a DetailSection on the Report, and added a TextBox for each column of the DataTable to the DetailSection.

The TextBoxes are databinding, but I can’t figure out what the proper Expression would be to access the column data for each TextBox.

The ReportItem.DataObject.RawData for each TextBox is a DataRowView.

In the Immediate window in Visual Studio, I can access the column data from within the TextBox DataBinding handler with the following:

((System.Data.DataRowView)(((Telerik.Reporting.Processing.TextBox)sender).DataObject.RawData))["ID"]

 Please tell me what Expression would access the column data. 

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 08 Nov 2023, 07:26 AM

Hello Michael,

We are already discussing the issue in the Support ticket on the same problem. I will share here some of the information that may be beneficial for other Telerik Reporting users.

Please, check the article Binding ObjectDataSource Component to a DataTable.

Generally, the Report DataSource exposes the fields/columns, and you may use an Expression like '=Fields.ID' to access the corresponding value in a TextBox or another report item. For more details, I recommend the Fields section of the article Global Objects Overview. The Expression '=Fields.ID' may be resolved only in the context of a data item - see Expression Scope.

Note that each data row triggers a new detail section generation for the Report or other data item. That said, in each detail section instance you will have the data from the corresponding data row of the DataTable.

If you need to access the entire data column, you may do this in the other Report sections, for example, in the Report Header. You may aggregate the values - see Aggregate Functions. You may also use a data item like a List or Table to display them all. In the latter case, the List will generate one detail section for each data row.

Regarding the ItemDataBinding event handler, you may be able to change the Value of the TextBox Processing item (namespace Telerik.Reporting.Processing). The new value will replace the value calculated by the Reporting engine from the Expression set in the Definition item (namespace Telerik.Reporting). By default, it is not possible to use Expressions for Values set in the report item events, as in these events you work with the Processing items as senders.

If you need to change the definition item Value in the event, which will let you provide a new Expression to the TextBox, you need to set the value of cacheDefinitionProperties in the Reporting Configuration processing Element to False (the default is True). See the KB article Changes on Items in Report Events Are Not Applied for additional information.

Regards,
Todor
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Tags
DataSources
Asked by
Michael
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or