Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void  RadioButton2_CheckedChanged(object sender, EventArgs e)
{
    int no1, no2;
    float ans;

    no1 = Convert.ToInt32("textbox2.Text");
    no2 = Convert.ToInt32("textbox3.Text");
    ans = no1 - no2;
    Label2.Text = ans.ToString();
}
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        int no1, no2;
        float ans;

        no1 = Convert.ToInt32("textbox2.Text");
        no2 = Convert.ToInt32("textbox3.Text");
        ans = no1 + no2;
        Label2.Text = ans.ToString();
    }
    protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
    {
        int no1, no2;
        float ans;

        no1 = Convert.ToInt32("textbox2.Text");
        no2 = Convert.ToInt32("textbox3.Text");


            ans = no1 * no2;
            Label2.Text = ans.ToString();

    }
    protected void RadioButton4_CheckedChanged(object sender, EventArgs e)
    {
        int no1, no2;
        float ans;

        no1 = Convert.ToInt16("textbox2.Text");
        no2 = Convert.ToInt16("textbox3.Text");
        ans = no1 /no2;
        Label2.Text =ans.ToString();
    }
Posted
Comments
Prasad_Kulkarni 13-Jun-13 8:55am    
Use Convert.ToString() instead of ToString().
Convert.ToString() handles null, while ToString() doesn't.

..and debug your code line by line, check what input you're giving and what will be the expected output.
CHill60 13-Jun-13 8:59am    
Nice explanation of why to use Convert in this instance
jkirkerx 13-Jun-13 15:15pm    
are the values in the textbozes really integers?, or perhaps decimals

I don't know why, but you are trying to convert the text "textbox1.Text" to an integer, not the value in the textbox:

C#
protected void  RadioButton2_CheckedChanged(object sender, EventArgs e)
{
    int no1, no2;
    float ans;
 
    no1 = Convert.ToInt32(textbox2.Text);    //THIS IS WHERE THE PROBLEM WAS ON
    no2 = Convert.ToInt32(textbox3.Text);    //ALL THESE LINES WITH QUOTES
    ans = no1 - no2;
    Label2.Text = ans.ToString();
}
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        int no1, no2;
        float ans;
 
        no1 = Convert.ToInt32(textbox2.Text);
        no2 = Convert.ToInt32(textbox3.Text);
        ans = no1 + no2;
        Label2.Text = ans.ToString();
    }
    protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
    {
        int no1, no2;
        float ans;
 
        no1 = Convert.ToInt32(textbox2.Text);
        no2 = Convert.ToInt32(textbox3.Text);
 

            ans = no1 * no2;
            Label2.Text = ans.ToString();
 
    }
    protected void RadioButton4_CheckedChanged(object sender, EventArgs e)
    {
        int no1, no2;
        float ans;
 
        no1 = Convert.ToInt16(textbox2.Text);
        no2 = Convert.ToInt16(textbox3.Text);
        ans = no1 /no2;
        Label2.Text =ans.ToString();
    }
 
Share this answer
 
Comments
Prasad_Kulkarni 13-Jun-13 9:05am    
5'ed!
Suppress the quotes when you're doing conversions ;)

Replace this
C#
Convert.ToInt32("textbox2.Text");

With that
C#
Convert.ToInt32(textbox2.Text);
 
Share this answer
 
Comments
Patel Shweta 13-Jun-13 9:14am    
still not display result in lable
Ahmed Bensaid 13-Jun-13 9:59am    
You have to set AutoPostBack property to true for each of your radiobuttons ;)
Patel Shweta 13-Jun-13 13:04pm    
Thank you .. its working :)
jkirkerx 13-Jun-13 15:16pm    
how about marking this as solved

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