I have a nested gridview:
<gridview id="gvParent" runat="server" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label Id="name" runat="server" Text='<%# Eval("Name")%>' />
<gridview id="gvChild" runat="server" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input type="text" id="Val1'<%# Eval("Identifiant")%>'" value='<%# Eval("Val1">' onchange= "CalculateSumRow(Val2'<%# Eval("Identifiant")%>');"/>
</ItemTemplate>
</asp:TemplateField>
<gridview id="gvChild" runat="server" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input type="text" id="Val2'<%# Eval("Identifiant")%>'" value='<%# Eval("Val2")%>' onchange="CalculateSumRow(Val2'<%# Eval("Identifiant")%>');"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<input type="text" id="TotalRealise<%# Eval("Identifiant")%>'" value='<%# Eval ("TotalRealise")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</gridview>
</ItemTemplate>
</asp:TemplateField>
</Columns>
In javascript function CalculateSumRow I make sum of val1 and val 2 per row in field TotalRealise and I need a total of fields TotalRealise.I try to make a javascript function that I called from CalculateSumRow .I try to parse row by row first grid , then second grid and I want to get all totalrealise fields and make a sum with this but I receive errors when I search the second grid.I want to make that calculation from javascript.
function CalculateSumRow (identifiant)
{
......
CalculateTotal();
}
function CalculateTotal()
{
var grdPar=document.getdocumentById('<%= gvParent%>');
for(row=1;row<grdPar.rows.length;row++)
{
var grdChild=document.getdocumentById('<%= gvChild%>');
for(rowC=1;row<grdChild.rows.length;rowC++)
{
alert(grdChild.rows[rowc].cell[3].value);
}
}
}
Can somebody help me make this sum ?
Thanks.
If you are comfortable using jQuery, try this:
Call the below function onchange event of input value:
This will give you sum of TotalRealise fields.