Export (0) Print
Expand All

Setting Layout in a RadioButtonList Web Server Control

Visual Studio .NET 2003

By default, the RadioButtonList Web server control displays a single column of buttons. However, you can specify any number of columns, and within the columns, you can specify how the items are ordered: vertically (the default) or horizontally. Vertical layout in three columns results in a layout such as the following:

A    D    G
B    E    H
C    F

Horizontal layout for the same items results in the following layout:

A    B    C
D    E    F
G    H
Note   If you are working with individual RadioButton Web server controls, you don't set layout as a property of the control. Instead, you set it by simply adding the radio buttons within the page flow. For details about the differences between these controls, see Introduction to the RadioButton and RadioButtonList Web Server Controls.

To specify column count and ordering:

  1. In the Properties window, set the RadioButtonList control's RepeatColumns property to the number of columns you want.
  2. Set the RepeatDirection property to Vertical or Horizontal. If you are setting the property in code, use the RepeatDirection enumeration, as shown in the following example:
    ' Visual Basic
    Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
       ' Create five radio buttons, labeled Red, Blue, Green, Yellow, and Orange.
       Dim colors() As String = _
          New String() {"Red", "Blue", "Green", "Yellow", "Orange"}
       Dim i As Integer
       For i = 0 To ubound(colors)
       ' Layout the radio buttons horizontally.
       RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal
    End Sub
    // C#
    public void Button1_Click (object sender, System.EventArgs e)
       // Create five radio buttons, labeled Red, Blue, Green, Yellow, and Orange.
       string[] colors = {"Red", "Blue", "Green", "Yellow", "Orange"};
       for(int i=0;i < colors.GetLength(0);i++){
       // Layout the radio buttons horizontally.
       this.RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal;

See Also

Adding RadioButtonList Controls to a Web Forms Page | Setting the Selection in a List Web Server Control | Determining the Selection in a List Web Server Control | Adding Items in a List Web Server Control | RadioButton Class | RadioButtonList Class

© 2015 Microsoft