大家好,目前我正在开发一个javascript函数,该函数需要在页脚行中显示gridview单元格的总和。现在我能够得到答案,但我无法将值保存在页脚行中。谁能帮我将值保存到gridview页脚标签。提前致谢。
这是我的js函数。
function addTotal() {
var input = document.getElementsByTagName("input");
var Total = '0.0';
var Sample;
var val;
for (var i = 0; i < input.length; i++) {
if (input[i].type == "text") {
if (input[i].id.indexOf("txtpercent") > 0) {
Sample = document.getElementById(input[i].id).value;
var val = parseFloat(Sample.replace(",", ""));
if (isNaN(val) == true) {
val = 0;
}
Total = parseFloat(Total) + val;
//document.getElementById("Flblallocationpercent").innerHTML=Total;
}
}
}
alert(Total);
if (Total != 100) {
alert("Allocation should be equal to 100 %")
return false;
}
}
这是调用函数的设计部分
<asp:TemplateField HeaderText="Allocation Percentage">
<ItemTemplate>
<asp:TextBox ID="txtpercent" runat="server" Text="" OnTextChanged="allocate_sum"
Visible="true" ToolTip="Percentage" onblur="addTotal()" />
</ItemTemplate>
<FooterTemplate >
<asp:Label ID="Flblallocationpercent" runat="server" Enabled="true" Width="95%" />
</FooterTemplate>
<FooterStyle HorizontalAlign="Center" Width="5%" />
<ItemStyle HorizontalAlign="Center" Width="5%" />
</asp:TemplateField>