Reputation: 21
i am having trouble in calculation in grid, i made function but it works only on 1st row of grid and calculate total of first row of grid and then show this value in grand total textbox too. I want to do the same on all 4 rows of grid, what do i do? Kindly help. function CalculateTotal() { var Gtot = 0;
var RowCount = 0;
//var RowCount = document.getElementById('<%= hfGrdRows.ClientID%>').value - 0;
//alert(RowCount);
var grid = document.getElementById('<%= Grd_Exams.ClientID%>');
for (var i = 1; i < grid.rows.length ; i++) {
var cell = grid.rows[i].cells;
//var HTML = cell[0].innerHTML;
var Participation = document.getElementById('txtCl_Part').value - 0;
var Assgnmnt = document.getElementById('txtAssgnmnt').value - 0;
var Quiz = document.getElementById('txtQuiz').value - 0;
var WrPaper = document.getElementById('txtWP').value - 0;
var OSME = document.getElementById('txtOSME').value - 0;
//for (var i = 1; i < grdLength - 1; i++) {
var Total = parseFloat(Participation) + parseFloat(Assgnmnt) + parseFloat(Quiz) + parseFloat(WrPaper) + parseFloat(OSME);
if (!isNaN(Total)) {
document.getElementById('txtTotal').value = Total;
}
else {
alert("Nikal");
}
}
var getTotal = document.getElementById('txtTotal').value - 0;
var Gtot = parseInt(Gtot) + parseFloat(getTotal);
if (!isNaN(Gtot)) {
document.getElementById('txtGTot').value = Gtot;
}
else {
alert("Cannot Show Total");
}
var Percentage = (parseFloat(Gtot) * 100) / 400;
if (!isNaN(Percentage)) {
document.getElementById('txtPercent').value = Percentage;
}
else {
alert("Cannot show percentage");
}
}
Upvotes: 0
Views: 1186
Reputation: 2405
Gridview is just a table
var table = document.getElementById("mytable");
for (var i = 0, row; row = table.rows[i]; i++) {
//row
for (var x = 0, col; col = row.cells[x]; x++) {
// column & column cell
if (x===0) {
//first column
var cell = row.cells[x];
// do something with cell
}
}
}
Upvotes: 2