Monday, December 4, 2023
 Popular · Latest · Hot · Upcoming
76
rated 0 times [  82] [ 6]  / answers: 1 / hits: 20718  / 15 Years ago, thu, may 28, 2009, 12:00:00

I have telerik RadGrid which is in edit mode. Each cell contains NumericTextBox. Is it possible to calculate one cell based on other cells in the same row (on client side).
For example if I have a row which contains cells like price and item I want on every change to calculate total price but on client side, without going to server side. Is this possible with RadGrid?


More From » asp.net

 Answers
66

Thanks for all your answers but I found the solution here at telerik forum. I'll just paste the solution here in case that somebody get stuck on the same issue.



ASPX:



<Columns> 
<rad:GridTemplateColumn UniqueName=Price HeaderText=Price>
<EditItemTemplate>
<radI:RadNumericTextBox ID=txtPrice runat=server>
</radI:RadNumericTextBox>
</EditItemTemplate>
</rad:GridTemplateColumn>
<rad:GridTemplateColumn UniqueName=Quantity HeaderText= Number of Items>
<EditItemTemplate>
<radI:RadNumericTextBox ID=txtQuantity runat=server>
</radI:RadNumericTextBox>
</EditItemTemplate>
</rad:GridTemplateColumn>
<rad:GridTemplateColumn UniqueName=TotalAmount HeaderText=Total>
<EditItemTemplate>
<radI:RadNumericTextBox ID=txtTotalAmount runat=server>
</radI:RadNumericTextBox>
</EditItemTemplate>
</rad:GridTemplateColumn>
</Columns>


C#



  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
{

if (e.Item is GridDataItem && e.Item.IsInEditMode)
{
GridDataItem item = (GridDataItem)e.Item;
RadNumericTextBox txtPrice= item.FindControl(txtPrice) as RadNumericTextBox; // Get the textbox for column Price
RadNumericTextBox txtQuantity= item.FindControl(txtQuantity) as RadNumericTextBox; // Get the textbox for column Quantity
RadNumericTextBox txtTotalAmount= item.FindControl(txtTotalAmount) as RadNumericTextBox; // Get the textbox for column TotalAmount, if it is template as shown in aspx

txtPrice.Attributes.Add(onFocusout, return calculate(' + txtPrice.ClientID + ',' + txtQuantity.ClientID + ',' + txtTotalAmount.ClientID + '));
txtQuantity.Attributes.Add(onFocusout, return calculate(' + txtPrice.ClientID + ',' + txtQuantity.ClientID + ',' + txtTotalAmount.ClientID + '));
txtTotalAmount.Attributes.Add(onfocus, return calculate(' + txtPrice.ClientID + ',' + txtQuantity.ClientID + ',' + txtTotalAmount.ClientID + '));
}
}


JavaScript:



<script type=text/javascript>  
function calculate(price, quantity, totalAmount)
{
var text1 = $find(price); //I used Asp.net Ajax find method
var text2 = $find(quantity);
var text3 = $find(totalAmount);
var total = text1.GetValue() * text2.GetValue();
text3.SetValue(total);
}
</script>

[#99441] Saturday, May 23, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daryldeontaeh

Total Points: 46
Total Questions: 97
Total Answers: 105

Location: Maldives
Member since Sat, Jan 29, 2022
2 Years ago
;