Click here to Skip to main content
15,946,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
I have a grid view which have multiple line .I am multiplying two values which have been shown in below syntax.but there is problem it will return amount of the last row.I have given syntax of to find total amount of each row.Please help me.

<script type="text/javascript" language="javascript">
function getMult()
for(var i=0;i<ctl00_ContentPlaceHolder1_GridView1.rows.length;i++)
var a=parseFloat(document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl03_txtqty").value);
var b=parseFloat(document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl03_txtrate").value);
var c=parseFloat(document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl03_txtamt").value);
var total=a*b;

Updated 30-Sep-10 0:36am

Well, it looks like you are only using 3rd row to calculate every time!
Look here: "ctl00_ContentPlaceHolder1_GridView1_ctl03_txtqty"

function getMult()
   for(var i=0;i<ctl00_ContentPlaceHolder1_GridView1.rows.length;i++)
     var a=parseFloat(document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl0"+i+"_txtqty").value);
     var b=parseFloat(document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl0"+i+"_txtrate").value);
     var c=parseFloat(document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl0"+i+"_txtamt").value);
     var total=a*b;parseFloat(document.getElementById("ctl00_Content;).valuetPlaceHolder1_GridView1_ctl0"+i+"_txtamt").value=total.toFixed(2));
Share this answer
Hi Amit,

Please use the following Javascript function to get result.

var grid = document.getElementById('<%=GridView1.ClientID %>');
      for (var r = 0; r < grid.rows.length; r++) {
          var row = grid.rows[r].getElementsByTagName('input');
          row[2].value = (row[0].value * row[1].value);

Please do let me know, if you have any doubt.

Please provide "Vote" if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Share this answer

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