15,850,359 members
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 1:53am
v2
muneebalikiyani 29-Aug-13 6:09am
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

## Solution 3

> 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);```

## Solution 4

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"`

## Solution 2

XML
```<asp:GridView ID="grdView" runat="server"  GridLines="None" Font-Size="15pt"
Width="486px">

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

<asp:Label ID="lblTotalPrice" runat="server" Text="0">```