It is not possible to check your complete code. I have modified my previous reply as per your gridview structure. Refer the below link.
http://www.aspforums.net/Threads/207781/Grand-total-of-a-Gridview-column-using-java-script/Replies/7#Replies
Naresh.rj says:
<script type=
"text/javascript"
>
$(
function
()
{
$(
"[id*=GtxtSubject1]"
).val(
"0"
);
$(
"[id*=GtxtSubject2]"
).val(
"0"
);
$(
"[id*=GtxtSubject3]"
).val(
"0"
);
});
$(
".calculate"
).live(
"keyup"
,
function
()
{
var
row = $(
this
).closest(
'tr'
);
var
Subject1 = $(row).find(
'[id*=GtxtSubject1]'
);
var
Subject2 = $(row).find(
'[id*=GtxtSubject2]'
);
var
Subject3 = $(row).find(
'[id*=GtxtSubject3]'
);
if
(!jQuery.trim($(Subject1).val()) ==
''
&& !jQuery.trim($(Subject2).val()) ==
''
&& !jQuery.trim($(Subject3).val()) ==
''
)
{
if
(!isNaN(parseFloat($(Subject1).val())) && !isNaN(parseFloat($(Subject2).val())) && !isNaN(parseFloat($(Subject2).val())))
{
$(
"[id*=GtxtTotal]"
, row).html(parseFloat($(Subject1).val()) + parseFloat($(Subject2).val()) + parseFloat($(Subject2).val()));
}
}
else
{
$(Subject1).val(
''
);
$(Subject2).val(
''
);
$(Subject2).val(
''
);
}
var
grandTotal = 0;
$(
"[id*=GtxtTotal]"
).each(
function
()
{
grandTotal = grandTotal + parseFloat($(
this
).html());
});
$(
"[id*=lblGrandTotal]"
).html(grandTotal.toString());
});
</script>
Also you have to write the code inside ready function like below. You have written out side ready function.
<script type="text/javascript">
$(function () {
$("[id*=GtxtSubject1]").val("0");
$("[id*=GtxtSubject2]").val("0");
$("[id*=GtxtSubject3]").val("0");
$(".calculate").live("keyup", function () {
var row = $(this).closest('tr');
var Subject1 = $(row).find('[id*=GtxtSubject1]');
var Subject2 = $(row).find('[id*=GtxtSubject2]');
var Subject3 = $(row).find('[id*=GtxtSubject3]');
if (!jQuery.trim($(Subject1).val()) == '' && !jQuery.trim($(Subject2).val()) == '' && !jQuery.trim($(Subject3).val()) == '') {
if (!isNaN(parseFloat($(Subject1).val())) && !isNaN(parseFloat($(Subject2).val())) && !isNaN(parseFloat($(Subject2).val()))) {
$("[id*=GtxtTotal]", row).html(parseFloat($(Subject1).val()) + parseFloat($(Subject2).val()) + parseFloat($(Subject2).val()));
}
}
else {
$(Subject1).val('');
$(Subject2).val('');
$(Subject2).val('');
}
var grandTotal = 0;
$("[id*=GtxtTotal]").each(function () {
grandTotal = grandTotal + parseFloat($(this).html());
});
$("[id*=lblGrandTotal]").html(grandTotal.toString());
});
});
</script>