Click here to Skip to main content
15,888,269 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to calculate total price and grand price from gridview values and from texbox for quantity.

i have a gridview and it has got 2 boundfield (description and price) and a textbox also. so i want to calculate total price based on price and entered quantity in that textbox and display it on the label inside the gridview
Posted
Updated 29-Aug-13 0:53am
v2
Comments
muneebalikiyani 29-Aug-13 6:09am    
Can't read your mind , what are u upto?
vinay.tatipamula 29-Aug-13 6:31am    
Where are you struck? or you want us to write the code for you?
Member 10239837 29-Aug-13 6:41am    
yes i would love you to write a code for me.

i wrote the code but it does not work

what i want exactly is that, i have a gridview with 2 boundfield, description and price and i also have a textbox(Qty) in that grid, so i want to calculate a total price for the entire row when you add a quantity to the textbox, i want it to calculate a total price and display it to the LAbel
[no name] 29-Aug-13 6:36am    
Sure thing. You calculate the value by using the addition (+), subtraction (-), multiplication (*) and division (/) operators.
vinay.tatipamula 29-Aug-13 6:50am    
:D

> i want the code that will allow me to calculate
> the total price from qty and price and display a grand price

C#
int quantity = 3;
decimal price = 41.99;

decimal totalPrice = price * quantity;

// jokeInCode: I have no idea what a grand price is. Something similar to the Laguna Seca Grand Prix?
// Jokes aside, is it something with a tax?

decimal tax = 0.073;

decimal grandPrice = totalPrice * (1 + tax);
 
Share this answer
 
Hi this is how I did mine but was calculating KM's

C#
double tot = 0;
int _count = 0;
decimal _sumKillometers = 0.0M;



C#
protected void grvTravelClaims_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblKM = (Label)e.Row.FindControl("lblKillometers");
                decimal _Killometers = Decimal.Parse(lblKM.Text);
                _sumKillometers += _Killometers;
                _count += 1;
            
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                Label lblKM = (Label)e.Row.FindControl("lblTot");
             
                double rate=Convert.ToDouble(txtRate.Text);
                double sum=Convert.ToDouble(_sumKillometers);
             
                lblKM.Text = (rate * sum).ToString();
                
            }
        }


Then thats how I called my event in the gridview


ASP
OnRowDataBound="grvTravelClaims_RowDataBound"
 
Share this answer
 
XML
<asp:GridView ID="grdView" runat="server"  GridLines="None" Font-Size="15pt"
        Width="486px">



            <asp:TemplateField HeaderText="Quantity">

                    <asp:TextBox ID="txtQty" runat="server" Height="16px" Width="38px">




            <asp:TemplateField HeaderText="Total Price">

                    <asp:Label ID="lblTotalPrice" runat="server" Text="0">
 
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