title: How to calculate and update RadGrid cell values on clientside using javascript
body: <p>I'm using RadGrid.</p>
  
  <p>I followed this post <a href="https://stackoverflow.com/questions/920682/how-to-calculate-radgrid-cell-value-on-client-side">@StackOverflow</a> and calling a javascript method to do some calculations on the cell and update another cell on the same row.</p>
  
  <ol>
  <li><p>It calls the Calculate method, but the cell value is not available the first time. If the cell gets focus again, then the value shows up in the Calculate(). This is the case in all rows.</p></li>
  <li><p>The target cell is updated with the calculated value on the second onBlur event, since the first onBlur doesn't bring the edited value. But when the focus goes to any other cell the target cell loses it's updated value and goes back to original value. I'm not calling any other javascript methods on any other cell events.</p></li>
  </ol>
  
  <blockquote>
    <p>My requirement is to calculate for eg., qtyCell and costCell and
    update amountCell on the clientside.</p>
  </blockquote>
  
  <pre><code>protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
  {  
      if (e.Item is GridDataItem)
      {
          GridDataItem item = (GridDataItem)e.Item;
          RadTextBox txtQty = item.FindControl("qty") as RadTextBox;
          RadTextBox txtAmount = item.FindControl("valued") as RadTextBox;
          RadTextBox txtUnitCost = item.FindControl("unitcost") as RadTextBox;
  
          if (txtQty != null &amp;&amp; txtAmount != null &amp;&amp; txtUnitCost != null)
          {
              txtQty.Attributes.Add("onBlur", "calculate('" + txtQty.ClientID + "','" + txtAmount.ClientID + "','" + txtUnitCost.ClientID + "')");
          }
      }  
  }
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;  
  function calculate(price, quantity, totalAmount)   //this method throws error
  {  
      //var text1 = $find(price);
      //var text2 = $find(quantity);  
      //var text3 = $find(totalAmount);  
      //var total = text1.GetValue() * text2.GetValue();  
      //text3.SetValue(total);  
  
      //commented out the above lines because .GetValue() and .SetValue() throws an error "Object does not support this method"
  
      var txtqty = $find(qtyCtrl);
      var txtunitcost = $find(unitcostCtrl);
      var txtvalued = $find(valuedCtrl);
  
      var qty = txtqty.get_displayValue();
      var unitcost = txtunitcost.get_displayValue();
      var amount = qty * unitcost;
      txtvalued.set_displayValue(amount);
  }  
  &lt;/script&gt;
  </code></pre>