RadioButton.GroupName Property
Gets or sets the name of the group that the radio button belongs to.
[Visual Basic] Public Overridable Property GroupName As String [C#] public virtual string GroupName {get; set;} [C++] public: __property virtual String* get_GroupName(); public: __property virtual void set_GroupName(String*); [JScript] public function get GroupName() : String; public function set GroupName(String);
Property Value
The name of the group that the radio button belongs to. The default is String.Empty.
Remarks
Use this property to specify a grouping of radio buttons to create a mutually exclusive set of controls. The property can be used when only one selection is possible from a list of available options.
When this property is set, only one RadioButton in the specified group can be selected at a time.
Example
[Visual Basic, C#, JScript] The following example illustrates how to programmatically set the GroupName property of the RadioButton class.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script language="VB" runat="server"> Sub Button1_Click(sender As Object, e As EventArgs) If Radio3.GroupName = "RegularMenu" Then Radio3.GroupName = "VegitarianMenu" Radio3.BackColor = System.Drawing.Color.LightGreen Else Radio3.GroupName = "RegularMenu" Radio3.BackColor = System.Drawing.Color.Pink End If End Sub </script> </head> <body> <h3>Panel Example</h3> <form runat=server> <asp:Label id="Label1" BackColor="Pink" Text="RegularMenu" runat="server"/> <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#] <%@ 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"/> <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> [JScript] <%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> <script language="JScript" runat="server"> function Button1_Click(sender, e : EventArgs) { 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"/> <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++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
RadioButton Class | RadioButton Members | System.Web.UI.WebControls Namespace