Click here to Skip to main content
14,736,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my Grid, i have 4 textboxes in item template.
Now i want apply one calculation formula on these textboxes.
I need to auto calculate txt4 value, when values in txt1, txt2, txt3 changed.
My formula is:
txt4 = txt1 + txt2 - txt3
How can i do this, on which event of grid, or on each textbox ontextchanged event.
Any sample code is helpful.
Thanks in advance.

1 solution

OK, so you convert the string values in the TextBoxs to the value types you need, such as Integer or Double, or Single, ..., validate the values, do the calculation and convert the resulting value to a string and put it in the TextBox you need. You'd probably handle the TextChanged event of your source TextBoxs to kick off a method that performs the validation and calculation.
Sergey Alexandrovich Kryukov 27-Feb-11 21:50pm
Enough said, 5.
Rohit.Net100 27-Feb-11 23:42pm
Any sample example ?
Dave Kreskowiak 28-Feb-11 16:08pm
Nope. I hardly ever do ASP.NET and/or Java work, but the overall procedure is still the same.
Rohit.Net100 28-Feb-11 10:54am

I am using below code for calculation column values in grid.
But i am getting Jscript error:
Microsoft JScript runtime error: 'ContentPlaceHolder1_GD_Prod_ctl00_ctl04_TxtPPort' is undefined.

Private Sub GD_Prod_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles GD_Prod.ItemCreated

If TypeOf e.Item Is GridDataItem Then
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
Dim T1 As TextBox = TryCast(item.FindControl("TxtPPort"), TextBox)
Dim T2 As TextBox = TryCast(item.FindControl("TxtBFPort"), TextBox)
Dim T3 As TextBox = TryCast(item.FindControl("TxtLOPort"), TextBox)
Dim T4 As TextBox = TryCast(item.FindControl("TxtTSPort"), TextBox)
T1.Attributes.Add("onblur", ((("Total(" + T1.ClientID & ",") + T2.ClientID & ",") + T3.ClientID & ",") + T4.ClientID & ")")
T2.Attributes.Add("onblur", ((("Total(" + T1.ClientID & ",") + T2.ClientID & ",") + T3.ClientID & ",") + T4.ClientID & ")")
T3.Attributes.Add("onblur", ((("Total(" + T1.ClientID & ",") + T2.ClientID & ",") + T3.ClientID & ",") + T4.ClientID & ")")
End If

End Sub

Client side code:
function Total(TxtPPort, TxtBFPort, TxtLOPort, TxtTSPort) {
TxtTSPort.value = parseInt(TxtPPort.value) + parseInt(TxtBFPort.value) - parseInt(TxtLOPort.value);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900