jquery - How to get a sum of column of GridView using JavaScript -
i'm trying access column named time of gridview , calculate sum of whole column using javascript.
i have this:
so in report total want number 5, since entry right now.
this definition of gridview:
<div class="total"> <asp:gridview id="reportgrid" runat="server" autogeneratecolumns="false" datasourceid="sqlds" height="68px" width="813px" allowpaging="true"> <columns> <asp:boundfield datafield="date" headertext="date" sortexpression="date" dataformatstring="{0:mm/dd/yy}" /> <asp:boundfield datafield="name" headertext="team member name" sortexpression="name" /> <asp:boundfield datafield="projectname" headertext="projects" sortexpression="projectname" /> <asp:boundfield datafield="description" headertext="description" sortexpression="description" /> <asp:boundfield datafield="time" headertext="time" sortexpression="time" /> </columns> </asp:gridview> <br /> <br /> <span>report total: <em> <asp:label runat="server" id="totalhours" text="0"></asp:label></em></span> </div>
can me javascript code problem or share me related links, cause i've found on internet wasn't similar this, , guess simple thing when know how use js.
nan value sum during debugging:
add css class fields
<asp:boundfield datafield="time" headertext="time"> <itemstyle cssclass="yourclass"></itemstyle> </asp:boundfield>
and use following code
var fields= document.getelementsbyclassname('yourclass'); var sum = 0; (var = 0; < fields.length; ++i) { var item = fields[i]; sum += parseint(item.innerhtml); }
and assign sum total label
$("#<%= totalhours.clientid %>").text(sum);
Comments
Post a Comment