Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey everyone,
I'm using a Gridview control to have users enter in line items for a purchase requsition. Within that Gridview six columns and one check box ,three columns are BoundField, if the check box is checked then want muliplay ,Total Price=Price*Quantity , Total Price is the label in the ItemTemplate, and Quantity is ItemTemplate in TextBox(txtQuantity),Price is the BoundField in DataBase Please Help me..i am also trying in javaScript But it Executed Please Help me
below is my UI and Code Beiond:

XML
<asp:GridView ID="GRVItem" DataKeyNames="ItemCode,ItemName" runat="server" Font-Names="Calibri"
                        Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B" AllowPaging="True" PageSize="5"
                        ShowHeader="true" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
                        Width="1000px" padding-top=" 70px;" AutoGenerateColumns="false">
                        <HeaderStyle BorderColor="Gray" BorderStyle="Solid" Font-Bold="true" BackColor="#76C3FD" />
                        <Columns>
                            <asp:TemplateField>
                            <ItemTemplate>
                                    <asp:CheckBox ID="chk" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox_CheckChanged" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Item Code" DataField="ItemCode" ReadOnly="true" />
                            <asp:BoundField HeaderText="Item Name" DataField="ItemName" ReadOnly="true" />
                            <asp:BoundField HeaderText="In Stack" DataField="OnHand" ReadOnly="true" />
                            <asp:BoundField HeaderText="Price" DataField="AvgPrice" ReadOnly="true" />
                            <asp:TemplateField HeaderText="Quantity">
                                <ItemStyle HorizontalAlign="center" Width="13%" />
                                <HeaderStyle HorizontalAlign="center" />
                                <ItemTemplate>
                                    <asp:TextBox ID="txtQuantity" runat="server" Width="50%"/>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Total Price">
                                <ItemStyle HorizontalAlign="center" Width="13%" />
                                <HeaderStyle HorizontalAlign="center" />
                                <ItemTemplate>
                                    <asp:Label runat="server" ID="lbltotPrice"></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

        function JvfunonBlur() {
            debugger;
            var grid = document.getElementById('<%=GRVItem.ClientID %>');
            var col1;
            var totalcol1 = 0;
            for (i = 0; i < grid.rows.length; i++) {
                col1 = grid.rows[i].cells[4];
                col2 = grid.rows[i].cells[5];

                for (j = 0; j < col1.childNodes.length; j++) {
                    if (col1.childNodes[j].type == "text") {
                        if (!isNaN(col1.childNodes[j].value) && col1.childNodes[j].value != "") {
                            totalcol1 += parseInt(col1.childNodes[j].value)
                        }
                    }
                }
            }
            document.getElementById('<%=Price.ClientID %>').value = totalcol1;
        }

Protected Sub GRVItem_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GRVItem.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim txt As Label = DirectCast(e.Row.FindControl("lbltotPrice"), Label)
            txt.Attributes.Add("onBlur", "JvfunonBlur();")

        End If
    End Sub
Posted
Updated 23-Aug-13 20:41pm
v2

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