返回首页

任何人都可以知道吗?

输入的字符串是不正确的format.how解决?

protected void totalprice()

    {

        int quantity = int.Parse("txtquantity");

     float price =float.Parse("price");

     float totalprice = float.Parse("totalPrice");

     totalprice=quantity * price;

}

回答

评论会员:乌玛・尚卡尔帕特尔 时间:2012/02/07
的希望txtquantity,价格,totalPrice variabeles

 int quantity = int.Parse(txtquantity);

     float price =float.Parse(price);

     float totalprice = float.Parse(totalPrice);

 

评论会员:游客 时间:2012/02/07
梅迪吴拉姆:您可能意味着以下(其中价格,totalprice和txtquantity对象):codeprelang="c#"spanclass="code-keyword"protected/spanspanclass="code-keyword"void/spantotalprice(){spanclass="code-keyword"int/spanquantity=spanclass="code-keyword"int/span.Parse(txtquantity.Text);spanclass="code-keyword"float/spanprice=float.Parse(price);spanclass="code-keyword"float/spantotalprice=spanclass="code-keyword"float/span.Parse(totalPrice);totalprice=quantity*price;}/pre/code的
爱德华・卢
评论会员:游客 时间:2012/02/07
使用Int.TryParse或Float.TryParse的是比铸造或直接转换输出值发生此错误时,试图将值转换是不可自由兑换所需的数据类型。的问候,爱德华
乌代・辛格
评论会员:游客 时间:2012/02/07
你需要学习在C#中的类型转换。有一个看看这些:imgsrc=http://www.orcode.com/img/ico/smiley_smile.gif{A}希望它可以帮助{S0}
KARTHIK Harve:你怎么能转换为整数字符串值"txtquantity"......?和"价格",进入浮动,"totalPrice"到浮法

如果这些文本框,然后尝试这个..

{体C3}
如果这些字符串变量,然后,试试这个..

{C4的saharkiz}
评论会员:游客 时间:2012/02/07
|我不明白您的problem.You试图整数转换成一个字符串值,并试图存储到整型变量,这是可以的。txtquantity是TextBox,那么你必须保存TextBox的值到变量江前计算总Price.See此代码。{C5的}这是你要财产以后的另一个输出执行calculation.If的正确方法,然后请解释你的问题在​​短暂​​的。MKB的
|你如何要转换字符串"txtquantity",一个整型值

也许你应该使用,东西像Request.Parameters ["txtquantity"。的ToString()或会议[的"txtquantity"。的ToString()或txtquntity.Text。

因此,试图找出你的价值的源泉,更仔细
评论会员:游客 时间:2012/02/07
|阿米尔Mahfoozi:看来你需要一个动态的序列发生器,所以尝试这一个:{5233}希望它帮助