Click here to Skip to main content
15,905,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai i my gridview i am having three columns Price,Quantity,Total Price, Price and TotalPrice are label and Quantity is the TextBox,now i need to total Price =Price*Quantity in Jquery or java script Please Help Me: Below is my code

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: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>
Posted

1 solution

Hi,
You need to do implement small Js function and call it on onblur of quantity text box.But make sure that u need to check that supplied parameters number or not.otherwise it will give as NAN error. u can use isNaN() function to chek that.


function Calculate(ctrl) {
var priceVal = $(ctrl).parent().parent().children(":first-child").html();
var qty = ctrl.value;
var totalPrice = priceVal * qty;
$(ctrl).parent().parent().children(":last-child").html(totalPrice);
}




<asp:gridview id="GRVItem" runat="server" font-names="Calibri" font-size="11pt" alternatingrowstyle-backcolor="#C2D69B" xmlns:asp="#unknown">
AllowPaging="True" PageSize="5" ShowHeader="true" CssClass="mGrid" PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt" Width="100%" padding-top=" 70px;" AutoGenerateColumns="false">
<HeaderStyle BorderColor="Gray" BorderStyle="Solid" Font-Bold="true" BackColor="#76C3FD" />
<columns> <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" onblur="javascript:return Calculate(this);" runat="server">
Width="30%" />


<asp:templatefield headertext="Total Price">
<itemstyle horizontalalign="center" width="13%">
<HeaderStyle HorizontalAlign="center" />
<itemtemplate>
<asp:label runat="server" id="lbltotPrice">


 
Share this answer
 

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