GroupName属性:此按钮所属组,如果不设置该属性,可以多选择
拖放两个RadioButton,设置GroupName,两个RadioButton添加同一个事件ReadioButton_CheckedChanged
<body>
<form id="form1" runat="server">
<div>
请选择您要学的方向:
<asp:RadioButton ID="rbCSharp" runat="server"
oncheckedchanged="ReadioButton_CheckedChanged" Text="C#"
AutoPostBack="true" GroupName="Language" />
<asp:RadioButton ID="rbJava" runat="server" Text="Java" GroupName="Language"
oncheckedchanged="ReadioButton_CheckedChanged" AutoPostBack="true" />
</div>
</form>
</body>
打开cs
protected void ReadioButton_CheckedChanged(object sender, EventArgs e)
{
if (rbCSharp.Checked)
{
Response.Write("您选择的是C#!");
}
else if (rbJava.Checked)
{
Response.Write("您选择的是Java!");
}
}