CheckBoxList.RepeatDirection Propiedad

Definición

Obtiene o establece un valor que indica si el control se muestra en vertical o en horizontal.

public:
 virtual property System::Web::UI::WebControls::RepeatDirection RepeatDirection { System::Web::UI::WebControls::RepeatDirection get(); void set(System::Web::UI::WebControls::RepeatDirection value); };
[System.ComponentModel.Bindable(true)]
public virtual System.Web.UI.WebControls.RepeatDirection RepeatDirection { get; set; }
public virtual System.Web.UI.WebControls.RepeatDirection RepeatDirection { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.RepeatDirection : System.Web.UI.WebControls.RepeatDirection with get, set
member this.RepeatDirection : System.Web.UI.WebControls.RepeatDirection with get, set
Public Overridable Property RepeatDirection As RepeatDirection

Valor de propiedad

Uno de los valores de RepeatDirection. De manera predeterminada, es Vertical.

Atributos

Excepciones

La dirección especificada en la que se muestra la lista no se corresponde con ninguno de los valores RepeatDirection.

Ejemplos

En el ejemplo de código siguiente se muestra cómo establecer la RepeatDirection propiedad para especificar que la dirección de visualización es vertical.

Nota

Los ejemplos de código siguientes usan el modelo de código de un solo archivo y es posible que no funcionen correctamente si se copian directamente en un archivo de código subyacente. Cada ejemplo de código debe copiarse en un archivo de texto vacío que tenga una extensión .aspx. Para obtener más información sobre el modelo de código de Web Forms, consulte ASP.NET Web Forms Modelo de código de página.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>CheckBoxList Example</title>
<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 id="form1" 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>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>CheckBoxList Example</title>
<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 id="form1" 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>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">
    <title> CheckBoxList RepeatDirection Example </title>
<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 direction that the items are rendered in the 
         // CheckBoxList control.
         checkboxlist1.RepeatDirection = (RepeatDirection)List.SelectedIndex;

      }

   </script>
 
</head>

<body>
   
   <form id="form1" runat="server">
 
      <h3> CheckBoxList RepeatDirection 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 direction to render the CheckBoxList items.

      <table cellpadding="5">

         <tr>

            <td>

               RepeatDirection:

            </td>

         </tr>

         <tr>

            <td>

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

                  <asp:ListItem>Horizontal</asp:ListItem>
                  <asp:ListItem Selected="True">Vertical</asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

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

</html>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">
    <title> CheckBoxList RepeatDirection Example </title>
<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 direction that the items are rendered in the 
         ' CheckBoxList control.
         checkboxlist1.RepeatDirection = _
             CType(List.SelectedIndex, RepeatDirection)

      End Sub

   </script>
 
</head>

<body>
   
   <form id="form1" runat="server">
 
      <h3> CheckBoxList RepeatDirection 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 direction to render the CheckBoxList items.

      <table cellpadding="5">

         <tr>

            <td>

               RepeatDirection:

            </td>

         </tr>

         <tr>

            <td>

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

                  <asp:ListItem>Horizontal</asp:ListItem>
                  <asp:ListItem Selected="True">Vertical</asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

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

</html>

Comentarios

Utilice esta propiedad para especificar la dirección de presentación del CheckBoxList control.

Nota

El número de columnas que se muestran siempre viene determinado por la RepeatColumns propiedad .

Si esta propiedad se establece RepeatDirection.Vertical en y si la RepeatLayout propiedad está establecida Tableen , la primera columna se rellena de arriba a abajo, la columna siguiente, etc. hasta que se representen todos los elementos. Por ejemplo, si la RepeatColumns propiedad se establece 3en , los elementos del CheckBoxList control se muestran en tres columnas, como en la tabla siguiente.

1 4 7
2 5 8
3 6 9

Si esta propiedad se establece RepeatDirection.Horizontal en y si la RepeatLayout propiedad está establecida Tableen , la primera columna se rellena de arriba a abajo, la columna siguiente, etc. hasta que se representen todos los elementos. Por ejemplo, si la RepeatColumns propiedad se establece 3en , los elementos del CheckBoxList control se muestran en filas de tres elementos cada uno, como en la tabla siguiente.

1 2 3
4 5 6
7 8 9

Se aplica a

Consulte también