Friday, 19 October 2012

access gridview in javascript

fetch values of template field
-----------------------------------------------------------
http://www.eggheadcafe.com/community/aspnet/3/10014375/need-to-get-value-of-gridview-template-columns-for-client-side-validation.aspx
--------------------------------------------------------------

function Calc(ob)
{
 var dtObj=document.getElementById('<%=lbltot.ClientID %>')
 
//  if(ob.value!="")
//  {
//     var res= parseInt(dtObj.innerText) + parseInt(ob.value);
//     document.getElementById('<%=lbltot.ClientID %>').innerText= res;
//  }
var res=0;
 var inputs = [];
 var i;
  inputs = document.getElementById("<%=GridView1.ClientID %>").getElementsByTagName("input");
  for (i in inputs)
   { 
     if (i != "length" && i.indexOf("Amt")!= -1) 
     { 
        if (isNaN(inputs[i].value) == true || inputs[i].value.length < 1) 
          continue;
        else
         res=res+ parseInt(inputs[i].value); 
      }
   }
document.getElementById('<%=lbltot.ClientID %>').innerText= res;
}

No comments:

Post a Comment