CheckBoxList.RepeatLayout Propriété

Définition

Obtient ou définit une valeur qui spécifie si la liste sera restituée à l'aide d'un élément table, d'un élément ul, d'un élément ol ou d'un élément span.

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

Valeur de propriété

Valeur qui spécifie si la liste sera restituée à l'aide d'un élément table, d'un élément ul, d'un élément ol ou d'un élément span. La valeur par défaut est Table.

Attributs

Exceptions

La mise en page spécifiée ne fait pas partie des valeurs RepeatLayout.

Exemples

L’exemple de code suivant montre comment utiliser la RepeatLayout propriété pour modifier le code HTML rendu par le CheckBoxList contrôle.

Notes

Les exemples de code suivants utilisent le modèle de code à fichier unique et peuvent ne pas fonctionner correctement s’ils sont copiés directement dans un fichier code-behind. Chaque exemple de code doit être copié dans un fichier texte vide qui a une extension .aspx. Pour plus d’informations sur le modèle de code Web Forms, consultez ASP.NET Web Forms Modèle de code de page.


<%@ 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 RepeatLayout 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 layout (table or flow) of the CheckBoxList control.
         checkboxlist1.RepeatLayout = (RepeatLayout)List.SelectedIndex;

      }

   </script>
 
</head>

<body>
   
   <form id="form1" runat="server">
 
      <h3> CheckBoxList RepeatLayout 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 whether to display the CheckBoxList control in 
      table or flow layout.

      <table cellpadding="5">

         <tr>

            <td>

               RepeatLayout:

            </td>

         </tr>

         <tr>

            <td>

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

                  <asp:ListItem Selected="True">Table</asp:ListItem>
                  <asp:ListItem>Flow</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 RepeatLayout 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 layout (table or flow) of the CheckBoxList control.
         checkboxlist1.RepeatLayout = CType(List.SelectedIndex, RepeatLayout)

      End Sub

   </script>
 
</head>

<body>
   
   <form id="form1" runat="server">
 
      <h3> CheckBoxList RepeatLayout 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 whether to display the CheckBoxList control in 
      table or flow layout.

      <table cellpadding="5">

         <tr>

            <td>

               RepeatLayout:

            </td>

         </tr>

         <tr>

            <td>

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

                  <asp:ListItem Selected="True">Table</asp:ListItem>
                  <asp:ListItem>Flow</asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

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

</html>

Remarques

Pour plus d’informations sur les options disponibles, consultez l’énumération RepeatLayout .

Notes

Deux options sont nouvelles à partir de ASP.NET 4 : OrderedList et UnorderedList.

Certains RepeatLayout paramètres n’autorisent pas la disposition horizontale. Pour plus d’informations, consultez l’énumération RepeatLayout.

S’applique à

Voir aussi