Click here to Skip to main content
14,735,180 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am using the code below to calculate grid column values using javascript.
It is working fine, but the problem is it wasn't calculating the last column of the grid.
I'd appreciate it if anyone couuld help me in this issue.
My code:
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)
        For Each item In GD_Prod.Items
            Dim txtbox1 As TextBox = DirectCast(item.FindControl("TxtSTUPort"), TextBox)
            Dim txtbox2 As TextBox = DirectCast(item.FindControl("TxtAAPort"), TextBox)
            Dim txtbox3 As TextBox = DirectCast(item.FindControl("STD_NUM_OF_SERVING"), TextBox)
            txtbox1.Attributes.Add("onblur", "show('" & txtbox1.ClientID & "','" & txtbox2.ClientID & "','" & txtbox3.ClientID & "');")
            txtbox2.Attributes.Add("onblur", "show('" & txtbox1.ClientID & "','" & txtbox2.ClientID & "','" & txtbox3.ClientID & "');")
            txtbox3.Attributes.Add("readonly", "readonly")
        Next
    End If
End Sub



Javascript code:
function show(TxtSTUPort, TxtAAPort, STD_NUM_OF_SERVING) {
    var TxtSTUPort = document.getElementById(TxtSTUPort);
    var TxtAAPort = document.getElementById(TxtAAPort);
    var STD_NUM_OF_SERVING = document.getElementById(STD_NUM_OF_SERVING);
    STD_NUM_OF_SERVING.value = parseInt(TxtSTUPort.value) + parseInt(TxtAAPort.value);
    if (!parseInt(STD_NUM_OF_SERVING.value)) {
        STD_NUM_OF_SERVING.value = '0';
    }
    // function is broken there is no closing brace to finish
    // the function and there seems to be some stuff missing


UPDATE:
Solved by OP himself. Posted as an answer.
Posted
Updated 9-Mar-11 22:24pm
v4
Comments
Manfred Rudolf Bihy 9-Mar-11 17:45pm
   
Edit: Grammar and spelling. Title for clarity. Added code pre tags. Fixed a broken &.

1 solution

Issue is resolved.

Instead using

If TypeOf e.Item Is GridDataItem Then
Dim item As GridDataItem = DirectCast(e.Item(), GridDataItem)

I replace code with

For Each item As GridDataItem In GD_Prod.Items
   

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