Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#

C#

i am calculating total amount of after calculating the percentage applied but getting an error of conversion as
:
C#
Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.IConvertible'.


What I have tried:

C#
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();
    }
}
Posted
Updated 16-Mar-16 22:56pm
v3

1 solution

Change
Quote:
amt1 = Math.Round(Convert.ToDouble (txtamt));

to
C#
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();

inside the txtexc_TextChanged event handler.
[/update]
 
Share this answer
 
v2
Comments
Member 12355460 17-Mar-16 5:37am    
it remove the error but now the solution is not show in the total textbox.
CPallini 17-Mar-16 6:01am    
See my updated solution.
Member 12355460 29-Mar-16 4:52am    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900