利用RadioButton控件进行职业选择

 答案:

本实例通过RadioButton控件列出3个职业名称进行单选,当选择其中的某一个选项时会弹出显示选项名称的对话框,运行结果如图1所示。

1  利用RadioButton控件进行职业选择

关键技术

RadioButton控件的CheckedChanged事件。

RadioButton控件的Text属性。

JavaScript脚本的alert方法。

实现过程

1)新建一个网站,默认主页名为Default.aspx

2)在Default.aspx页面中添加3RadioButton控件,分别双击这3RadioButton控件,在控件的CheckedChanged中编写代码。

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)

    {

        if (RadioButton1.Checked == true)

        {

            Response.Write("<script language=javascript>alert('你所从事的职业是:" + RadioButton1.Text.ToString() + "');</script>");

 

        }

    }

    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)

    {

        if (RadioButton2.Checked == true)

        {

            Response.Write("<script language=javascript>alert('你所从事的职业是:" + RadioButton2.Text.ToString() + "');</script>");

 

        }

    }

    protected void RadioButton3_CheckedChanged(object sender, EventArgs e)

    {

        if (RadioButton3.Checked == true)

        {

            Response.Write("<script language=javascript>alert('你所从事的职业是:" + RadioButton3.Text.ToString() + "');</script>");

 

        }

    }