Unable to get the value of textbox on expression

8 posts, 0 answers
  1. Iris
    Iris avatar
    32 posts
    Member since:
    Jul 2012

    Posted 15 Jan 2013 Link to this post

    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.
  2. Peter
    Admin
    Peter avatar
    1652 posts

    Posted 17 Jan 2013 Link to this post

    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!

  3. Iris
    Iris avatar
    32 posts
    Member since:
    Jul 2012

    Posted 18 Jan 2013 Link to this post

    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?
  4. Peter
    Admin
    Peter avatar
    1652 posts

    Posted 21 Jan 2013 Link to this post

    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!

  5. Paul
    Paul avatar
    1 posts
    Member since:
    Apr 2014

    Posted 10 Apr 2014 in reply to Iris Link to this post

    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
  6. Nasko
    Admin
    Nasko avatar
    1051 posts

    Posted 15 Apr 2014 Link to this post

    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.

     
  7. vinit
    vinit avatar
    2 posts
    Member since:
    Feb 2015

    Posted 26 Feb 2015 in reply to Nasko Link to this post

    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..
  8. KS
    KS avatar
    165 posts
    Member since:
    Oct 2012

    Posted 02 Mar 2015 in reply to vinit Link to this post

    Hi,

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

    -KS
Back to Top