HOW TO:設定 RadioButtonList Web 伺服器控制項中的配置

更新:2007 年 11 月

根據預設,RadioButtonList Web 伺服器控制項會顯示按鈕的單一欄位。然而,您可以指定任意的欄位數,且在這些欄位中,您可以指定項目的排列:垂直 (預設值) 或水平。在三個欄位垂直配置會產生類似下列的配置:

A    D    G
B    E    H
C    F

相同項目的水平配置會產生下列配置:

A    B    C
D    E    F
G    H
注意事項:

如果使用個別的 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 伺服器控制項概觀