日期:2014-05-18  浏览次数:20481 次

单选控件radiobutton的属性问题!简单。着急!
我想设置2个单选按钮   ,但是在后台代码里要做判断选了那项。请问用radiobutton的哪个属性?多谢。我是刚学.net   的。大家见谅

------解决方案--------------------
应该使用Checked属性,例如:

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;
}
}

------解决方案--------------------
完整点的MSDN示例如下:

下面的示例演示如何使用 RadioButton 控件为用户提供一组互斥的选项。

<%@ Page Language= "C# " AutoEventWireup= "True " %>
<html>
<head>

<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 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> <p>

<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> <p>

<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> <p>

<asp:button text= "Submit " OnClick= "SubmitBtn_Click " runat=server/>

<asp:Label id=Label1 font-bold= "true " runat= "server " />

</form>

</body>
</html>