如何:设置 RadioButtonList Web 服务器控件中的布局

更新:2007 年 11 月

默认情况下,RadioButtonList Web 服务器控件只显示一列按钮。但您可以指定任意列数,在这些列中,还可以指定各项的排序方式:垂直(默认)或水平。三列垂直布局如下所示:

A    D    G
B    E    H
C    F

相同项的水平布局产生以下布局:

A    B    C
D    E    F
G    H
y837ez6f.alert_note(zh-cn,VS.90).gif说明:

如果使用的是单个 RadioButton Web 服务器控件,请不要将布局设置为控件的属性。与此相反,您只需在页流内添加单选按钮即可。有关这些控件之间的差异的详细信息,请参见 RadioButton 和 RadioButtonList Web 服务器控件概述

指定列计数与排序

  1. RadioButtonList 控件的 RepeatColumns 属性设置为所需的列数。

  2. 使用 RepeatDirection 枚举将 RepeatDirection 属性设置为 Vertical 或 Horizontal,如下面的代码示例所示。

    Protected Sub Button1_Click(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Button1.Click
       ' Create five radio buttons.
       Dim colors() As String = _
          New String() {"Red", "Blue", "Green", "Yellow", "Orange"}
       RadioButtonList1.Items.Clear()
       Dim i As Integer
       For i = 0 To ubound(colors)
          RadioButtonList1.Items.Add(colors(i))
       Next
       ' Lay out the radio buttons horizontally.
       RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal
    End Sub
    
    protected void Button1_Click (object sender, System.EventArgs e)
    {
       // Create five radio buttons.
       string[] colors = {"Red", "Blue", "Green", "Yellow", "Orange"};
       this.RadioButtonList1.Items.Clear();
       for(int i=0;i < colors.GetLength(0);i++){
          this.RadioButtonList1.Items.Add(colors[i]);
       }   
       // Lay out the radio buttons horizontally.
       this.RadioButtonList1.RepeatDirection = 
           RepeatDirection.Horizontal;
    }
    

请参见

参考

RadioButton 和 RadioButtonList Web 服务器控件概述