RadioButtonList Class
Represents a list control that encapsulates a group of radio button controls.
For a list of all members of this type, see RadioButtonList Members.
System.Object
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.ListControl
System.Web.UI.WebControls.RadioButtonList
[Visual Basic] Public Class RadioButtonList Inherits ListControl Implements IRepeatInfoUser, INamingContainer, _ IPostBackDataHandler [C#] public class RadioButtonList : ListControl, IRepeatInfoUser, INamingContainer, IPostBackDataHandler [C++] public __gc class RadioButtonList : public ListControl, IRepeatInfoUser, INamingContainer, IPostBackDataHandler [JScript] public class RadioButtonList extends ListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
The RadioButtonList control provides page developers with a single-selection radio button group that can be dynamically generated through data binding. It contains an Items collection with members that correspond to individual items on the list. To determine which item is selected, test the SelectedItem property of the list.
You can specify the rendering of the list with the RepeatLayout and RepeatDirection properties. If RepeatLayout is set to RepeatLayout.Table (the default setting), the list will be rendered within a table. If it is set to RepeatLayout.Flow, the list will be rendered without any tabular structure. By default, RepeatDirection is set to RepeatDirection.Vertical. Setting this property to RepeatDirection.Horizontal will render the list horizontally.
CAUTION This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. ASP.NET provides an input request validation feature to block script and HTML in user input. Validation server controls are also provided to assess user input. For more information, see Validation Server Controls.
Example
[Visual Basic, C#, JScript] The following example demonstrates how to programmatically modify the display of a RadioButtonList control.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script language="VB" runat="server"> Sub Button1_Click(Source As Object, e As EventArgs) If RadioButtonList1.SelectedIndex > - 1 Then Label1.Text = "You selected: " & RadioButtonList1.SelectedItem.Text End If End Sub Sub chkLayout_CheckedChanged(sender As Object, e As EventArgs) If chkLayout.Checked = True Then RadioButtonList1.RepeatLayout = RepeatLayout.Table Else RadioButtonList1.RepeatLayout = RepeatLayout.Flow End If End Sub Sub chkDirection_CheckedChanged(sender As Object, e As EventArgs) If chkDirection.Checked = True Then RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal Else RadioButtonList1.RepeatDirection = RepeatDirection.Vertical End If End Sub </script> </head> <body> <h3>RadioButtonList Example</h3> <form runat=server> <asp:RadioButtonList id=RadioButtonList1 runat="server"> <asp:ListItem>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> <asp:ListItem>Item 4</asp:ListItem> <asp:ListItem>Item 5</asp:ListItem> <asp:ListItem>Item 6</asp:ListItem> </asp:RadioButtonList> <p> <asp:CheckBox id=chkLayout OnCheckedChanged="chkLayout_CheckedChanged" Text="Display Table Layout" Checked=true AutoPostBack="true" runat="server" /> <br> <asp:CheckBox id=chkDirection OnCheckedChanged="chkDirection_CheckedChanged" Text="Display Horizontally" AutoPostBack="true" runat="server" /> <p> <asp:Button id=Button1 Text="Submit" onclick="Button1_Click" runat="server"/> <p> <asp:Label id=Label1 font-name="Verdana" font-size="8pt" runat="server"/> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script language="C#" runat="server"> void Button1_Click(object Source, EventArgs e) { if (RadioButtonList1.SelectedIndex > -1) { Label1.Text = "You selected: " + RadioButtonList1.SelectedItem.Text; } } void chkLayout_CheckedChanged(Object sender, EventArgs e) { if (chkLayout.Checked == true) { RadioButtonList1.RepeatLayout = RepeatLayout.Table; } else { RadioButtonList1.RepeatLayout = RepeatLayout.Flow; } } void chkDirection_CheckedChanged(Object sender, EventArgs e) { if (chkDirection.Checked == true) { RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal; } else { RadioButtonList1.RepeatDirection = RepeatDirection.Vertical; } } </script> </head> <body> <h3>RadioButtonList Example</h3> <form runat=server> <asp:RadioButtonList id=RadioButtonList1 runat="server"> <asp:ListItem>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> <asp:ListItem>Item 4</asp:ListItem> <asp:ListItem>Item 5</asp:ListItem> <asp:ListItem>Item 6</asp:ListItem> </asp:RadioButtonList> <p> <asp:CheckBox id=chkLayout OnCheckedChanged="chkLayout_CheckedChanged" Text="Display Table Layout" Checked=true AutoPostBack="true" runat="server" /> <br> <asp:CheckBox id=chkDirection OnCheckedChanged="chkDirection_CheckedChanged" Text="Display Horizontally" AutoPostBack="true" runat="server" /> <p> <asp:Button id=Button1 Text="Submit" onclick="Button1_Click" runat="server"/> <p> <asp:Label id=Label1 font-name="Verdana" font-size="8pt" runat="server"/> </form> </body> </html> [JScript] <%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> <script language="JScript" runat="server"> function Button1_Click(Source : System.Object, e : EventArgs) { if (RadioButtonList1.SelectedIndex > -1) { Label1.Text = "You selected: " + RadioButtonList1.SelectedItem.Text; } } function chkLayout_CheckedChanged(sender : System.Object, e : EventArgs) { if (chkLayout.Checked == true) { RadioButtonList1.RepeatLayout = RepeatLayout.Table; } else { RadioButtonList1.RepeatLayout = RepeatLayout.Flow; } } function chkDirection_CheckedChanged(sender : System.Object, e : EventArgs) { if (chkDirection.Checked == true) { RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal; } else { RadioButtonList1.RepeatDirection = RepeatDirection.Vertical; } } </script> </head> <body> <h3>RadioButtonList Example</h3> <form runat=server> <asp:RadioButtonList id=RadioButtonList1 runat="server"> <asp:ListItem>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> <asp:ListItem>Item 4</asp:ListItem> <asp:ListItem>Item 5</asp:ListItem> <asp:ListItem>Item 6</asp:ListItem> </asp:RadioButtonList> <p> <asp:CheckBox id=chkLayout OnCheckedChanged="chkLayout_CheckedChanged" Text="Display Table Layout" Checked=true AutoPostBack="true" runat="server" /> <br> <asp:CheckBox id=chkDirection OnCheckedChanged="chkDirection_CheckedChanged" Text="Display Horizontally" AutoPostBack="true" runat="server" /> <p> <asp:Button id=Button1 Text="Submit" onclick="Button1_Click" runat="server"/> <p> <asp:Label id=Label1 font-name="Verdana" font-size="8pt" 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
Namespace: System.Web.UI.WebControls
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
Assembly: System.Web (in System.Web.dll)
See Also
RadioButtonList Members | System.Web.UI.WebControls Namespace | ListControl | RepeatDirection | RepeatLayout