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

Unable to get the value of textbox on expression

8 Answers 475 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Iris
Top achievements
Rank 1
Iris asked on 16 Jan 2013, 04:04 AM
I have 4 textboxes in my report, namely totalPriceTextBox, totalCostTextBox, textBox1 and textBox2.

The value for totalPriceTextBox and totalCostTextBox are from datasource fields.

The value for textBox1 is defined as:
=Fields.TotalPrice - Fields.TotalCost

The value for textBox2 is defined as:
=textBox1.Value / Fields.TotalCost * 100

When I view this report in the Preview tab, totalPriceTextBox, totalCostTextBox are textBox1 are successfully displayed. However I get the error as displayed below for textbox2:
An error has occurred while processing Textbox 'textbox2':
The expression contains object 'textbox1' that is not defined in the current context

Can anyone help me on this? Thank you.

8 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 17 Jan 2013, 12:15 PM
Hello Iris,

In expressions you can't directly reference other report items. Instead our suggestion is to update your expression as shown in the following example:
=(Fields.TotalPrice - Fields.TotalCost)/ Fields.TotalCost * 100

Kind regards,
Peter
the Telerik team

HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Iris
Top achievements
Rank 1
answered on 18 Jan 2013, 08:17 AM
First of all, thank you for your suggestion. While your suggestion is valid, it requires the same calculation to be done every time a textbox is bound, instead of reusing the result of the calculation done previously.

For your info, the example that I gave on my first post was the simplified version of my report. In my actual report, there are some textboxes with expressions like this:
=SUM(Fields.TotalPrice - Fields.TotalCost)

I also have some textboxes where I need to calculate this:
=SUM(Fields.TotalPrice - Fields.TotalCost) /  SUM(Fields.TotalPrice) * 100

If I just use this expression (=SUM(Fields.TotalPrice - Fields.TotalCost) /  SUM(Fields.TotalPrice) * 100), I will need to calculate SUM(Fields.TotalPrice - Fields.TotalCost) and SUM(Fields.TotalPrice) again for each textbox. Let's say I have many rows of data, won't this affect the time taken to display the report?
0
Peter
Telerik team
answered on 21 Jan 2013, 08:41 AM
Hello Iris,

The reporting engine should quickly handle such expressions. Our suggestion is to make some tests to check what is the performance impact of this expression. Still if you require to access another processing report item value you can utilize the following user function:
public static object GetProcessingItemValue(
    Processing.ReportItem currentReportItem,
    string targetReportItemName)
{
    var targetReportItem = Processing.ElementTreeHelper.GetChildByName(
        currentReportItem.ParentElement,
        targetReportItemName) as Processing.TextBox;
 
    return targetReportItem.Value;
}
However have in mind that the order of report item processing is dependent on the order report items are added to it's parent Items collection. Thus the user function will only work if you utilize it from report item that is added to the items collection (designer) after it's target report item.

Regards,
Peter
the Telerik team

HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Paul
Top achievements
Rank 1
answered on 10 Apr 2014, 01:47 PM
Hello Peter,

I also have a simular problem.....
I need to filter a table on a report dynamically with the value of a textbox on the same report

Could you please tell me which parameters i need to use to call 
GetProcessingItemValue( Processing.ReportItem currentReportItem, string targetReportItemName)

Thanks Paul
0
Nasko
Telerik team
answered on 15 Apr 2014, 11:56 AM
Hello Paul,

The approach suggested by my colleague won't work in every scenario, as he has described after the provided code snippet. Since the TextBox.Value in question is probably coming from a data source, it is best to create a user function, or modify your data source to return a calculated field, which returns the same value and can be used in the table Filtering expression.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
vinit
Top achievements
Rank 1
answered on 26 Feb 2015, 06:03 AM
I have the same problem i.e there are two textboxes into my report which contains Names and Percentage
TextBox1=fields.Name
Textbox2=IIf(IsNull(Fields.Registant,0)=0,0,CDbl(Fields.Registant)/ exec("Report1",CDbl(Sum(Fields.Registant))))

and i want a textbox on footer which contains the value like
TextBox3=Sum(Textbox2)  i have tried something like
Sum(IIf(IsNull(Fields.Registant,0)=0,0,CDbl(Fields.Registant)/ exec("Report1",CDbl(Sum(Fields.Registant)))))
but did not work..
0
KS
Top achievements
Rank 1
answered on 02 Mar 2015, 02:40 PM
Hi,

Try to put the whole expression in Exec or PageExec (the latter is for Page Footer).

-KS
0
AP
Top achievements
Rank 1
Veteran
answered on 02 Jul 2020, 07:51 AM

Hi telerik team,

      I have two text boxes in my report. First textbox have hardcoded value 5. Now i need to get the value of the first textbox and do some calculation in second textbox. In this situation what can i do? Please help me. Thanks.

 

Tags
General Discussions
Asked by
Iris
Top achievements
Rank 1
Answers by
Peter
Telerik team
Iris
Top achievements
Rank 1
Paul
Top achievements
Rank 1
Nasko
Telerik team
vinit
Top achievements
Rank 1
KS
Top achievements
Rank 1
AP
Top achievements
Rank 1
Veteran
Share this question
or