Click here to Skip to main content
14,641,699 members
Rate this:
Please Sign up or sign in to vote.
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 JavaScript.how to find total amount of each row.Please help me.
thanks.


<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;
parseFloat(document.getElementById("ctl00_Content;).value

tPlaceHolder1_GridView1_ctl03_txtamt").value=total.toFixed(2));
}
}
</script>
Posted
Updated 30-Sep-10 0:36am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

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

Try:
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));
   }
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

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:

Thanks,
Imdadhusen
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100