日期:2014-05-19  浏览次数:21173 次

怎么让RedioButton按自己要求分组?
如题!

------解决方案--------------------
使用groupname属性,看例子:

<%@ Page Language= "C# " AutoEventWireup= "True " %>
<html>
<head>
<script language= "C# " runat= "server ">

void Button1_Click(Object sender, EventArgs e) {
if (Radio3.GroupName == "RegularMenu ") {
Radio3.GroupName = "VegitarianMenu ";
Radio3.BackColor = System.Drawing.Color.LightGreen;
}
else {
Radio3.GroupName = "RegularMenu ";
Radio3.BackColor = System.Drawing.Color.Pink;
}
}

</script>
</head>
<body>

<h3> Panel Example </h3>

<form runat=server>

<asp:Label id= "Label1 " BackColor= "Pink " Text= "RegularMenu " runat= "server "/>
&nbsp;

<asp:Label id= "Label2 " BackColor= "LightGreen " Text= "VegitarianMenu " runat= "server "/>
<p>

<asp:RadioButton id= "Radio1 " GroupName= "RegularMenu "
Text= "Beef " BackColor= "Pink " runat= "server "/>

<p>
<asp:RadioButton id= "Radio2 " GroupName= "RegularMenu "
Text= "Pork " BackColor= "Pink " runat= "server "/>

<p>
<asp:RadioButton id= "Radio3 " GroupName= "RegularMenu "
Text= "Fish " BackColor= "Pink " runat= "server "/>

<p>
<asp:RadioButton id= "Radio4 " GroupName= "VegitarianMenu "
Text= "Mushroom " BackColor= "LightGreen " runat= "server "/>

<p>
<asp:RadioButton id= "Radio5 " GroupName= "VegitarianMenu "
Text= "Tofu " BackColor= "LightGreen " runat= "server "/>

<p>
<asp:Button id= "Button1 " OnClick= "Button1_Click "
Text= "Regroup the radio buttons " runat= "server "/>

</form>

</body>
</html>

------解决方案--------------------
用容器类控件分组...
------解决方案--------------------
C#中,System.Windows.Forms.RadioButton只能通过GroupBox进行分组。
RadioButton没有那个属性控制自己与哪些其他的RadioButton进行分组。

所以还是用GroupBox吧!
------解决方案--------------------
帮忙顶,接分
------解决方案--------------------
没有别的办法,只能放置到容器当中。