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

minus 2 template field with javascript

1 Answer 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
niloofar
Top achievements
Rank 1
niloofar asked on 16 Jan 2011, 11:40 AM
hi
i have 3 templatefield

 <telerik:GridTemplateColumn HeaderText="????">
                    <ItemTemplate>
                    <asp:Label ID="lblPrice" runat="server" Text='<%# CDS.Savin.WebUI.Generals.General.numberToMoney(Eval("Price").ToString()) %>' ></asp:Label>
                    </ItemTemplate>
                    </telerik:GridTemplateColumn>
                     <telerik:GridTemplateColumn HeaderText="?????">
                    <ItemTemplate>
                    <asp:TextBox runat="server" ID="txtDiscount" OnKeyUp="keyupHandler1();" ></asp:TextBox>
                    </ItemTemplate>
                    </telerik:GridTemplateColumn>
                       <telerik:GridTemplateColumn HeaderText="???? ??" >
                    <ItemTemplate>
                    <asp:Label runat="server" ID="lblTotalPrice"></asp:Label>
                    </ItemTemplate>
                    </telerik:GridTemplateColumn>
when user type number in to "txtDiscount " i want :lblTotalPrice.Text=lblPrice.text-txtDiscount.Text
please help to me
thanks

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Jan 2011, 06:43 AM
 Hello Niloofar,

You can attach the 'onkeyup' event to the TextBox from code behind and pass the ID of txtDiscount, lblPrice, lblTotalPrice to the client event handler. Then you can do the required calculations from client side as shown below. 

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
  {
      if (e.Item is GridDataItem)
      {
          GridDataItem item = (GridDataItem)e.Item;
          TextBox txtDiscount = (TextBox)item.FindControl("txtDiscount");    
          Label lblPrice = (Label)item.FindControl("lblPrice");
          Label lblTotalPrice = (Label)item.FindControl("lblTotalPrice");
          txtDiscount.Attributes.Add("onkeyup", "return keyupHandler1('" + txtDiscount.ClientID + "','" + lblPrice.ClientID + "','" + lblTotalPrice.ClientID + "')");
      }
  }

JavaScript:
function keyupHandler1(txtBoxId1, lblID, txtBoxId2)
  {
      var txtDiscount = document.getElementById(txtBoxId1);
      var lblPrice = document.getElementById(lblID);
      var lblTotalPrice = document.getElementById(txtBoxId2);
      lblTotalPrice.innerHTML = parseInt(lblPrice.innerHTML) - parseInt(txtDiscount.value);
   
  }

Thanks,
Shinu.
Tags
Grid
Asked by
niloofar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or