locked
Gridview footer template textbox not Calculating rate*Quantity = Total RRS feed

  • Question

  • User-807418713 posted

    Hello

    This is my javascript

    <script type="text/javascript">
        function FootLabel()
        {
            var txtFirstNumberValue = document.getElementById('ctl00_ContentPlaceHolder1_Label10').innerText;
            var txtSecondNumberValue = document.getElementById('ctl00_ContentPlaceHolder1_GridView3_ctl10_FPW').value;
             var result =  parseFloat(txtFirstNumberValue) * parseFloat(txtSecondNumberValue);
             document.getElementById("ctl00_ContentPlaceHolder1_GridView3_ctl10_FAQ").value = result;
            
           
            
        }
    </script>

    its not working gridview footertemplate textbox why

    some times it coming ctl10, some time ctl12,

    any best method to solve this issue

    im using asp.net with Masterpage

    Tuesday, October 23, 2018 12:27 PM

Answers

  • User839733648 posted

    Hi 

    According to your description and code, I suggest that you could add specific ids to the column of rate,Quantity,Total in FootTemplete and then set the values.

    You have to add ClientIDMode="Static" to the related labels.

    You could modify your code as below.

                var txtFirstNumberValue = document.getElementById("rateTotal").innerHTML;
                var txtSecondNumberValue = document.getElementById("quantityTotal").innerHTML;
                document.getElementById("AvgTotal").innerHTML = parseFloat(txtSecondNumberValue) * parseFloat(txtFirstNumberValue);
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowFooter="true">
    ...
            <Columns>
    ...
                <asp:TemplateField HeaderText="Rate">
    ...
                    <FooterTemplate>
                        <asp:Label ID="rateTotal" runat="server" ClientIDMode="Static"></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Quantity">
    ...
                    <FooterTemplate>
                        <asp:Label ID="quantityTotal" runat="server" ClientIDMode="Static"></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Avg">
    ...
                    <FooterTemplate>
                        <asp:Label ID="AvgTotal" runat="server" ClientIDMode="Static"></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </asp:Content>

    result like this:

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 24, 2018 4:46 AM