当你把一个数字放在乘客数量时,我如何编码计算的cs部分? [英] How can I code the cs part of the computation where the totalfare updates when you put the a number in passenger count?

查看:76
本文介绍了当你把一个数字放在乘客数量时,我如何编码计算的cs部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何编制计算代码,您需要在乘客数量中加上数字,总票价会更新。票价是不变的。所以计算就像(乘客数*票价=总票价)。请帮帮我非常感谢



我尝试过:



I dont know how to code the computation where you need to put number in passenger count and the total fare will update. The fare is constant. So the computation is like (passenger count * fare = totalfare). Please help me Thank you very much

What I have tried:

<pre> <div class="col-sm-12">
                    <div class="col-sm-3">              
                        <asp:Label ID="Label3" runat="server" Text="Passenger Count: "></asp:Label>
                    </div>
                    <div class="col-sm-5">
                        <asp:TextBox ID="txtpasscount" runat="server" CssClass="textbox" required="true" ></asp:TextBox>
                    </div>
                   
                </div>
         <div class="col-sm-12">
                    <div class="col-sm-3">              
                        <asp:Label ID="Label1" runat="server" Text="Fare: "></asp:Label>
                    </div>
                    <div class="col-sm-5">
                        <asp:TextBox ID="txtfare" runat="server" CssClass="textbox" required="true" ></asp:TextBox>
                    </div>
                   
                </div>
         <div class="col-sm-12">
                    <div class="col-sm-3">              
                        <asp:Label ID="Label2" runat="server" Text="Total Fare: "></asp:Label>
                    </div>
                    <div class="col-sm-5">
                        <asp:TextBox ID="totalfare" runat="server" Enabled="false" CssClass="textbox" required="true" ></asp:TextBox>
                    </div>
                   
                </div>

推荐答案

double fare = 0;
     int count = 0;
     double _totalFare = 0;
     if (double.TryParse(txtfare.Text.Trim(), out fare) && int.TryParse(txtpasscount.Text.Trim(), out count))
     {
         _totalFare = fare * count;
         totalfare.Text = _totalFare.ToString();
     }
     else
     {
         // throw error message, to enter the valid number
     }



参考

Double.TryParse方法(系统) [ ^ ]

int.TryParse [ ^ ]


这篇关于当你把一个数字放在乘客数量时,我如何编码计算的cs部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆