![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
<title>RadioButton Example</title>
<script language="C#" runat="server">
void SubmitBtn_Click(Object Sender, EventArgs e) {
if (Radio1.Checked) {
Label1.Text = "You selected " + Radio1.Text;
}
else if (Radio2.Checked) {
Label1.Text = "You selected " + Radio2.Text;
}
else if (Radio3.Checked) {
Label1.Text = "You selected " + Radio3.Text;
}
}
</script>
</head>
<body>
<h3>RadioButton Example</h3>
<form id="form1" runat="server">
<h4>Select the type of installation you want to perform:</h4>
<asp:RadioButton id="Radio1" Text="Typical" Checked="True" GroupName="RadioGroup1" runat="server" /><br />
This option installs the features most typically used. <i>Requires 1.2 MB disk space.</i><br />
<asp:RadioButton id="Radio2" Text="Compact" GroupName="RadioGroup1" runat="server"/><br />
This option installs the minimum files required to run the product. <i>Requires 350 KB disk space.</i><br />
<asp:RadioButton id="Radio3" runat="server" Text="Full" GroupName="RadioGroup1" /><br />
This option installs all features for the product. <i>Requires 4.3 MB disk space.</i><br />
<asp:button ID="Button1" text="Submit" OnClick="SubmitBtn_Click" runat="server"/>
<asp:Label id="Label1" font-bold="true" runat="server" />
</form>
</body>
</html>
checked发生变化时触发onCheckedChanged事件
上面的例子中并没有申明oncheckedchanged事件,而在bottonclick中来分析radiobutton组中的checked情况
常见的是这种方式
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
下面说下通过数据绑定控件生成一系列radiobutton时出现的问题
所有的groupname不是一致的,因此需要些个onclick()函数调用javascript
注意onclick()不是radiobutton的事件
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
function CancelSelect(obj)
{
elem=obj.form.elements;
for(i=0;i<elem.length;i++)
{
if (elem[i].type=="radio" && elem[i].id != obj.id)
{
elem[i].checked = false;
}
}
}