转换中出错 [英] Getting an error in conversion

查看:85
本文介绍了转换中出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在计算计算后的总金额已应用百分比但收到转换错误



i am calculating total amount of after calculating the percentage applied but getting an error of conversion as
:

Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.IConvertible'.





我尝试过:





What I have tried:

public partial class caltxt : System.Web.UI.Page
{
   double amt1;
    double exc;
    public void Page_Load(object sender, EventArgs e)
    {
       
    }

    public void txtamt_TextChanged(object sender, EventArgs e)
    {

         amt1 = Math.Round(Convert.ToDouble (txtamt));
        
        //decimal PercentageRate = Convert.ToDecimal(this.txtamt.Text);
   
    }


    protected void txtexc_TextChanged(object sender, EventArgs e)
    {
             
        double exc = Math.Round (Convert.ToDouble(this.txtexc.Text));
       
        
        // decimal    temp = (Math.Round(Convert.ToDecimal(txtexc.Text) / Convert.ToDecimal(txtamt.Text)*100));
       // txttotalexc.Text = temp.ToString();
    }

    protected void txttotalexc_TextChanged(object sender, EventArgs e)
    {
        double totat = Math.Round (Convert.ToDouble(exc) /100)* Convert.ToDouble(amt1); //+ Convert.ToInt32(this.txtexc.Text);
        this.txttotalexc.Text = totat.ToString();
    }
}

推荐答案

更改

Change
Quote:

amt1 = Math.Round(Convert.ToDouble(txtamt));

amt1 = Math.Round(Convert.ToDouble (txtamt));



to


to

amt1 = Math.Round(Convert.ToDouble (txtamt.Text));







[更新]

您还必须移动




[update]
You also have to move

Quote:

double totat = Math.Round(Convert.ToDouble(exc)/ 100)* Convert.ToDouble(amt1); // + Convert.ToInt32(this.txtexc.Text);

this.txttotalexc.Text = totat.ToString();

double totat = Math.Round (Convert.ToDouble(exc) /100)* Convert.ToDouble(amt1); //+ Convert.ToInt32(this.txtexc.Text);
this.txttotalexc.Text = totat.ToString();



里面的 txtexc_TextChanged 事件处理程序。

[/ update]


这篇关于转换中出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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