Rent textbox
service tax textbox
Gross rent textbox
i am adding rent and serice tax output will be displayed in gross rent.
i write caluation code in txt_tax as below
private void txt_tax_TextChanged(object sender, EventArgs e)
{
int a, b, c;
a = Convert.ToInt32(txt_rent.Text);
b = Convert.ToInt32(txt_tax.Text);
c = a + b;
txt_grossrent.Text = c.ToString();
}
for example i type service tax amount as 1000 then i clear the 1000 amount
the error occurs as Input string was not in a correct format.
please help me.please give the correct code.
Regards
Narsiman

Posted Jun 18, 2012, 2:05 AM EDT
if (!string.IsNullOrEmpty(txt_rent.Text))
a = Convert.ToInt32(txt_rent.Text);
if (!string.IsNullOrEmpty(txt_tax.Text))
b = Convert.ToInt32(txt_tax.Text);
c= a+b;
txt_grossrent.Text =Convert.ToString(c);
Please try this code.
Before doing the Convert.ToInt32 check the value of input. whether it is null or empty. Otherwise you can use, Int.tryparse method also for Convert.ToInt32 function.
VulpesRank #55 · 29.2K reputationPosted Jun 18, 2012, 2:13 AM EDT