views:

67

answers:

2

i wrote following code to do some of a specifice column of gridview.. but its not working please tell me were i am missing...

function ManipulateGrid()
    {
        var gvDrv = document.getElementById("<%= GridView1.ClientID %>");
        var gt=0.0;
        for (i=1; i<gvDrv.rows.length; i++)
        {
          var cell = gvDrv.rows[i].cells;
          var valold = cell[7].innerHTML;
          var val = 0.0;
          if(isNaN(parseFloat(valold)))
          {
          val=0.0;
          else
          val =valold;
          }
          gt = parseFloat (gt) + val;
        }
        alert(gt);
    }
+3  A: 

It's in and around your bracketed if block. You need to change the if block, and not throw away the conversion results.

if(isNaN(parseFloat(valold)))
{
    val= 0.0;
}
else
{
    val = parseFloat(valold);
}

Or even better:

var parsed = parseFloat(valold);
if(isNaN(parsed ))
{
    val= 0.0;
}
else
{
    val = parsed;
}
David M
wow its working thanks a lot..
Rajesh Rolen- DotNet Developer
+1  A: 

You haven't closed the curly brace for the if condition properly. Should be something like

var valueToCheck = parseFloat(valold);

if(isNaN(valueToCheck))
{
    val= 0.0;
}
else
{
    val = valueToCheck;
}
rahul