Click here to Skip to main content
15,994,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Please I would like to get the sum or total of my total column values in the txtFootTotal text box. I can already multiply quantity and price and the value is shown in the total column so now i need to sum the total values and show the same in the textbox at the footer. Please note that my gridview textboxes are not calling back data from the database they are unbound.

Here is my gridview

 <asp:GridView ID="grvbill" runat="server"
                ShowFooter="True" AutoGenerateColumns="False"
                CellPadding="4" ForeColor="#333333"
                GridLines="None" >
    <Columns>
        <asp:BoundField DataField="RowNumber" HeaderText="SNo" />
        <asp:TemplateField HeaderText="quantity">
            <ItemTemplate>
                <asp:TextBox ID="qty" runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="unit price">
            <ItemTemplate>
                <asp:TextBox ID="price" runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="all total">
            <ItemTemplate>
                <asp:TextBox ID="total" runat="server"
                   Height="55px" TextMode="MultiLine"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
       <asp:TemplateField HeaderText="">
            <ItemTemplate>

            </ItemTemplate>
            <FooterStyle HorizontalAlign="Right" />
            <FooterTemplate>
            <asp:TextBox ID="txtFootTotal" runat="server" Width="100px" Wrap="true" style="position:relative; right:500px;"></asp:TextBox>
                <asp:Button ID="ButtonAdd" runat="server"
                        Text="Add New Row" OnClick="ButtonAdd_Click" />
            </FooterTemplate>
        </asp:TemplateField>
           </Columns>
    <FooterStyle BackColor="" Font-Bold="True" ForeColor="" />
    <RowStyle BackColor="" />
    <EditRowStyle BackColor="" />
    <SelectedRowStyle BackColor="" Font-Bold="True" ForeColor="" />
    <PagerStyle BackColor="" ForeColor="" HorizontalAlign="Center" />
    <HeaderStyle BackColor="" Font-Bold="true" ForeColor="" />
    <AlternatingRowStyle BackColor="" />
</asp:GridView>


my javascript to do multiplication

<script type="text/javascript" language="javascript">
    function dowork(a, b, res) {
        document.getElementById(res).value = parseInt(document.getElementById(a).value, 10) * parseInt(document.getElementById(b).value, 10);
    }
</script>


my code behind in VB

Protected Sub grvbill_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles grvbill.RowDataBound

        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim boxa As TextBox = TryCast(e.Row.FindControl("qty"), TextBox)
            Dim boxb As TextBox = TryCast(e.Row.FindControl("price"), TextBox)
            Dim boxc As TextBox = TryCast(e.Row.FindControl("total"), TextBox)

            boxb.Attributes.Add("onkeyup", "dowork('" + boxa.ClientID + "','" + boxb.ClientID + "','" + boxc.ClientID + "')")
        End If
    End Sub


Thanks.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900