次の方法で共有


CheckBoxList.RepeatColumns プロパティ

CheckBoxList コントロールに表示する列数を取得または設定します。

Public Overridable Property RepeatColumns As Integer
[C#]
public virtual int RepeatColumns {get; set;}
[C++]
public: __property virtual int get_RepeatColumns();public: __property virtual void set_RepeatColumns(int);
[JScript]
public function get RepeatColumns() : int;public function set RepeatColumns(int);

プロパティ値

CheckBoxList コントロールに表示する列数。既定値は 0 です。このプロパティが設定されていないことを示します。

例外

例外の種類 条件
ArgumentOutOfRangeException 列数が負の値に設定されています。

解説

このプロパティを使用して、 CheckBoxList コントロールに項目を表示する列数を指定します。このプロパティを設定しない場合、 CheckBoxList コントロールはリストのすべての項目を 1 列に表示します。

使用例

[Visual Basic, C#, JScript] RepeatColumns プロパティを使用して、 CheckBoxList コントロールで 2 列を表示する方法を次の例に示します。

 
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>

<script language="VB" runat="server">

   Sub Check_Clicked(sender As Object, e As EventArgs)
      Dim i As Integer
      Message.Text = "Selected Item(s):<br><br>"
      For i=0 To checkboxlist1.Items.Count - 1
         If checkboxlist1.Items(i).Selected Then
            Message.Text += checkboxlist1.Items(i).Text + "<br>"
         End If
      Next
   End Sub

</script>
 
</head>
<body>
   
   <form action="checkboxlist.aspx" method="post" runat="server">
 
      <h3>CheckBoxList Example</h3>

      <asp:CheckBoxList id="checkboxlist1" 
           AutoPostBack="True"
           CellPadding="5"
           CellSpacing="5"
           RepeatColumns="2"
           RepeatDirection="Vertical"
           RepeatLayout="Flow"
           TextAlign="Right"
           OnSelectedIndexChanged="Check_Clicked"
           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:CheckBoxList>
 
      <br><br>

      <asp:label id="Message" runat="server"/>
             
   </form>
          
</body>
</html>

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>

<script language="C#" runat="server">

   void Check_Clicked(Object sender, EventArgs e) 
   {
      Message.Text = "Selected Item(s):<br><br>";
      for (int i=0; i<checkboxlist1.Items.Count; i++)
      {
         if (checkboxlist1.Items[i].Selected)
            Message.Text += checkboxlist1.Items[i].Text + "<br>";
      }
   }

</script>
 
</head>
<body>
   
   <form action="checkboxlist.aspx" method="post" runat="server">
 
      <h3>CheckBoxList Example</h3>

      <asp:CheckBoxList id="checkboxlist1" 
           AutoPostBack="True"
           CellPadding="5"
           CellSpacing="5"
           RepeatColumns="2"
           RepeatDirection="Vertical"
           RepeatLayout="Flow"
           TextAlign="Right"
           OnSelectedIndexChanged="Check_Clicked"
           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:CheckBoxList>
 
      <br><br>

      <asp:label id="Message" runat="server"/>
             
   </form>
          
</body>
</html>

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>
<html>
<head>

<script language="JScript" runat="server">

   function Check_Clicked(sender : Object, e : EventArgs) 
   {
      Message.Text = "Selected Item(s):<br><br>";
      for (var i : int = 0; i<checkboxlist1.Items.Count; i++)
      {
         if (checkboxlist1.Items[i].Selected)
            Message.Text += checkboxlist1.Items[i].Text + "<br>";
      }
   }

</script>
 
</head>
<body>
   
   <form action="checkboxlist.aspx" method="post" runat="server">
 
      <h3>CheckBoxList Example</h3>

      <asp:CheckBoxList id="checkboxlist1" 
           AutoPostBack="True"
           CellPadding="5"
           CellSpacing="5"
           RepeatColumns="2"
           RepeatDirection="Vertical"
           RepeatLayout="Flow"
           TextAlign="Right"
           OnSelectedIndexChanged="Check_Clicked"
           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:CheckBoxList>
 
      <br><br>

      <asp:label id="Message" runat="server"/>
             
   </form>
          
</body>
</html>

[Visual Basic] 

<%@ Page Language="VB" AutoEventWireup="True" %>

<html>

<head>

   <script runat="server">

      Sub Check_Clicked(sender as Object, e As EventArgs) 

         Message.Text = "Selected Item(s):<br><br>"

         ' Iterate through the Items collection of the CheckBoxList
         ' control and display the selected items.
         Dim i As Integer

         For i=0 To checkboxlist1.Items.Count - 1

            If checkboxlist1.Items(i).Selected Then

               Message.Text &= checkboxlist1.Items(i).Text & "<br>"

            End If

         Next

      End Sub

      Sub Index_Change(sender as Object, e As EventArgs) 

         ' Set the number columns in the CheckBoxList control.
         checkboxlist1.RepeatColumns = List.SelectedIndex

      End Sub

   </script>
 
</head>

<body>
   
   <form runat="server">
 
      <h3> CheckBoxList RepeatColumns Example </h3>

      Select items from the CheckBoxList.

      <br><br>

      <asp:CheckBoxList id="checkboxlist1" 
           AutoPostBack="True"
           CellPadding="5"
           CellSpacing="5"
           RepeatColumns="2"
           RepeatDirection="Vertical"
           RepeatLayout="Table"
           TextAlign="Right"
           OnSelectedIndexChanged="Check_Clicked"
           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:CheckBoxList>
 
      <br><br>

      <asp:label id="Message" runat="server"/>

      <hr>

      Select the number of columns to display.

      <table cellpadding="5">

         <tr>

            <td>

               RepeatColumns:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="List"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Index_Change"
                    runat="server">

                  <asp:ListItem>0</asp:ListItem>
                  <asp:ListItem>1</asp:ListItem>
                  <asp:ListItem Selected="True">2</asp:ListItem>
                  <asp:ListItem>3</asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

      </table>
             
   </form>
          
</body>

</html>


[C#] 

<%@ Page Language="C#" AutoEventWireup="True" %>

<html>

<head>

   <script runat="server">

      void Check_Clicked(Object sender, EventArgs e) 
      {

         Message.Text = "Selected Item(s):<br><br>";

         // Iterate through the Items collection of the CheckBoxList 
         // control and display the selected items.
         for (int i=0; i<checkboxlist1.Items.Count; i++)
         {

            if (checkboxlist1.Items[i].Selected)
            {

               Message.Text += checkboxlist1.Items[i].Text + "<br>";

            }

         }

      }

      void Index_Change(Object sender, EventArgs e) 
      {

         // Set the number columns in the CheckBoxList control.
         checkboxlist1.RepeatColumns = List.SelectedIndex;

      }

   </script>
 
</head>

<body>
   
   <form runat="server">
 
      <h3> CheckBoxList RepeatColumns Example </h3>

      Select items from the CheckBoxList.

      <br><br>

      <asp:CheckBoxList id="checkboxlist1" 
           AutoPostBack="True"
           CellPadding="5"
           CellSpacing="5"
           RepeatColumns="2"
           RepeatDirection="Vertical"
           RepeatLayout="Table"
           TextAlign="Right"
           OnSelectedIndexChanged="Check_Clicked"
           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:CheckBoxList>
 
      <br><br>

      <asp:label id="Message" runat="server"/>

      <hr>

      Select the number of columns to display.

      <table cellpadding="5">

         <tr>

            <td>

               RepeatColumns:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="List"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Index_Change"
                    runat="server">

                  <asp:ListItem>0</asp:ListItem>
                  <asp:ListItem>1</asp:ListItem>
                  <asp:ListItem Selected="True">2</asp:ListItem>
                  <asp:ListItem>3</asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

      </table>
             
   </form>
          
</body>

</html>

[C++] C++ のサンプルはありません。Visual Basic、C#、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

参照

CheckBoxList クラス | CheckBoxList メンバ | System.Web.UI.WebControls 名前空間 | RepeatDirection | RepeatLayout