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

Sum Textbox Values

7 Answers 933 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 30 Sep 2008, 08:01 PM

I have a textbox in my detail section that gets a value from a user function. I need to sum all of those textbox values in the report footer, but I can’t get it to work. Is there a way to use the SUM function on textbox values instead of data fields?

7 Answers, 1 is accepted

Sort by
0
Milen | Product Manager @DX
Telerik team
answered on 01 Oct 2008, 09:15 AM
Hi David,

Aggregate functions can be applied on any expression, not only on fields. So, in order to achieve the desired result, if your user function is called MyUserDefinedFunction and is applied on field MyField in the mentioned detail text box, you can use the expression

=SUM(MyUserDefinedFunction(Fields.MyField))

in the summary text box.

No, there is no convenient way to access the text rendered in one textbox item from another textbox item.

I hope you will find this information helpful.

Sincerely yours,
Milen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Deepak Shakya
Top achievements
Rank 1
answered on 15 Feb 2011, 05:03 AM
Hi Milen,

I know the post is old but I ran into same problem. The solution you gave uses "Fields.MyField" as parameter to the user function. But I want to pass a textbox value and not a field. The textbox in the deatil section uses the user defined function (with no parameters) to get the value.

When I put the name of the textbox (Fields.TextBoxName) in the user defined function, it gives me an error stating that it is not defined in the current context.

Any help will be appreciated.

I am using Q3 2010 Release.
0
Steve
Telerik team
answered on 15 Feb 2011, 05:40 PM
Hi Deepak,

Check the following KB article that elaborates on the possible reasons for this error: The expression contains undefined function call MyUserFunction() error.

Regards,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Deepak Shakya
Top achievements
Rank 1
answered on 18 Feb 2011, 03:36 AM
Hi Steve,

Thanks for the reply. I could get the sum for the textbox by using Userfunction. But for this I had change my report properties to be static. This could be a problem.

Initially, I populate the textbox in the detail section using "ItemDataBound" method of the textbox as it uses values from report properties to perform the calculation. Could you please tell me if there is a way to calculate the sum of this textbox in the groupfooter when the textbox value is populated using the ItemDataBound method rather than UserFunction or Fields.FieldName.

I used: =Sum(TextboxName) but it gives me error stating that it does not exist in the current context.

Method used to populate textbox:
private void fldChangeTextBox_ItemDataBound(object sender, EventArgs e)
        {
            double _value = 0;
            Telerik.Reporting.Processing.TextBox item = sender as Telerik.Reporting.Processing.TextBox;
            if ((!IsMissingValue) && (BaseLoad != 0))
            {
                _value = (ModelLoad - BaseReport1.BaseLoad);
                item.Value = string.Format("{0:N1}", _value);
            }
            else
            {
                item.Value = "-";
            }
 
        }

0
Deepak Shakya
Top achievements
Rank 1
answered on 12 May 2011, 08:08 AM
Hi,

Could you please send me an example where you can sum the textbox values? The values in the textbox is calculated/derived and not from any fields in the database/datasource.

Kind regards,
Deepak
0
Steve
Telerik team
answered on 17 May 2011, 03:44 PM
Hello Deepak,

Your scenario is pretty confusing to us as you state: "The values in the textbox is calculated/derived and not from any fields in the database/datasource." We are not aware how/where you calculate/derive the data and what is the expected result.
Generally following your logic, in this case you should calculate/aggregate the values in another textbox the same way you have calculated/derived them in the one used for showing the values.
If you're still having problems, please provide us with a sample runnable report that shows what you're after and we would get back to you with more accurate response.

Kind regards,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Deepak Shakya
Top achievements
Rank 1
answered on 18 May 2011, 02:36 AM
Hi Steve,

Thanks for the reply. I got it working now. Basically, I had a textbox (say, tbA) that got its value from one of the Fields in the database. I then added another textbox (say, tbB) that would get a value depending the value of tbA. I wrote a Userfunction as you suggested to get the value for tbB. The user function used the argument/variable that stored the value of tbA. (Using ItemDataBound)

I then added a textbox in the group header to calculate the subtotal. This subtotal textbox used a aggregate function that I wrote to get the total of tbB.

You had provided with the solution and it was all there. I just needed to learn how to implement it. Now that it is working I can use User function and custom aggregate more often.

Many thanks!
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Milen | Product Manager @DX
Telerik team
Deepak Shakya
Top achievements
Rank 1
Steve
Telerik team
Share this question
or