更新时间:2023-11-27 23:34:58
>内的标签上我想要的代码可以让我计算
>来自数量和价格的总价格并显示一个宏大的价格int quantity = 3 ;
十进制 price = 41 。 99 跨度>;
十进制 totalPrice = price * quantity;
// jokeInCode:我不知道价格是多少。类似于拉古纳塞卡大奖赛的东西?
// 除了笑话,它是什么的税?
十进制 tax = 0 。 073 跨度>;
decimal grandPrice = totalPrice *( 1 + tax);
嗨这就是我的做法,但我在计算KM的double tot = 0 ;
int _count = 0 ;
decimal _sumKillometers = 0 .0M;
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 =(标签)e.Row.FindControl( lblTot);
double rate = Convert.ToDouble(txtRate.Text);
double sum = Convert.ToDouble(_sumKillometers);
lblKM.Text =(rate * sum).ToString();
}
}
那就是我如何在gridview中调用我的事件OnRowDataBound =grvTravelClaims_RowDataBound
< asp:GridView ID = grdView runat = server GridLines = 无 字体大小 = 15pt
宽度 = 486px >
< asp:TemplateField HeaderText = 数量 >
< asp:TextBox ID = txtQty runat = server 高度 = 16px 宽度 = 38px >
< ; asp:TemplateField HeaderText = 总价格 >
< asp:Label ID = lblTotalPrice runat = server 文字 = 0 >
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
> i want the code that will allow me to calculate
> the total price from qty and price and display a grand priceint 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);
Hi this is how I did mine but was calculating KM'sdouble tot = 0; int _count = 0; decimal _sumKillometers = 0.0M;
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 gridviewOnRowDataBound="grvTravelClaims_RowDataBound"
<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">