如何根据asp.net中的单选按钮更改/附加标签的值?

时间:2017-05-15 12:25:16

标签: c# asp.net

protected void Rb1_CheckedChanged(object sender, EventArgs e)
{

    RadioButton rd = (RadioButton)sender;
    switch(rd.Text)
    {
        case "Liner":
            int a = 0;

            lbResult.Text = Convert.ToString(a);
            int lbltxt1 = Convert.ToInt32(lbResult.Text);
           lbltxt1 = lbltxt1 + a ;
            lbResult.Text = Convert.ToString(lbltxt1);
            break;
        case "Glossy":
            int b = 40;
            int lbltxt2 = Convert.ToInt32(lbResult.Text);
            lbltxt2 = lbltxt2 + b;
            lbResult.Text = Convert.ToString(lbltxt2);
            break;
        case "Matte":
            int c = 30;
            int lbltxt3 = Convert.ToInt32(lbResult.Text);
            lbltxt3 = lbltxt3 + c;
            lbResult.Text = Convert.ToString(lbltxt3);
            break;
        case "Dull":
            int d = 20;
            int lbltxt4 = Convert.ToInt32(lbResult.Text);
            lbltxt4 = lbltxt4 + d;
            lbResult.Text = Convert.ToString(lbltxt4);
            break;
        case "Woove":
            int f = 60;
            int lbltxt5 = Convert.ToInt32(lbResult.Text);
            lbltxt5 = lbltxt5 + f;
            lbResult.Text = Convert.ToString(lbltxt5);
            break;
        case "Laid":
            int g= 45;
            int lbltxt6 = Convert.ToInt32(lbResult.Text);
            lbltxt6 = lbltxt6 + g;
            lbResult.Text = Convert.ToString(lbltxt6);
            break;
    }


}

在此,如果我选择名为“Glossy”的单选按钮,那么lbResult标签的值将变为40,但如果我更改或重新选择另一个单选按钮,如“dull”然后它增加了沉闷和光泽(40 + 20 = 60)的值,标签显示60。 我想如果我重新选择任何其他单选按钮,该值只是成为该单选按钮的值而不是添加两个值 例如:如果我在“Glossy”之后选择“dull”,则标签的值变为20

1 个答案:

答案 0 :(得分:0)

包括lbResult.Text =“0”;在Rb1_CheckedChanged事件的开头。

     protected void Rb1_CheckedChanged(object sender, EventArgs e)
        {

            lbResult.Text = "0";
...