CheckBoxList.TextAlign Propriété

Définition

Obtient ou définit l'alignement du texte des cases à cocher du groupe.

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

Valeur de propriété

Une des valeurs de l'objet TextAlign. La valeur par défaut est Right.

Attributs

Exceptions

L'alignement spécifié du texte des étiquettes n'est pas l'une des valeurs TextAlign.

Exemples

L’exemple de code suivant montre comment utiliser la TextAlign propriété pour spécifier que le texte associé aux cases à cocher s’affiche à droite du 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>
    <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 TextAlign 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 alignment of the caption (right or left) in relation
         // to the check boxes.
         // Note that the TextAlign enumeration starts at 1 instead of 0, 
         // so the value of the SelectedIndex property cannot be used
         // directly for casting into a TextAlign enumeration.

         // In this example, the values of the TextAlign enumeration are 
         // stored in the Value property of each ListItem in the 
         // DropDownList control named List. To determine the enumeration  
         // value, retrieve the value of the Value property, convert it to
         // an Int32, and then cast it to a TextAlign enumeration.
         int EnumValue = Convert.ToInt32(List.SelectedItem.Value);

         checkboxlist1.TextAlign = (TextAlign)EnumValue;

      }

   </script>
 
</head>

<body>
   
   <form id="form1" runat="server">
 
      <h3> CheckBoxList TextAlign 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 captions to the right or the left 
      of the check boxes.

      <table cellpadding="5">

         <tr>

            <td>

               TextAlign:

            </td>

         </tr>

         <tr>

            <td>

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

                  <asp:ListItem Value="1">Left</asp:ListItem>
                  <asp:ListItem Value="2" Selected="True">Right</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 TextAlign 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 alignment of the caption (right or left) in relation
         ' to the check boxes.
         ' Note that the TextAlign enumeration starts at 1 instead of 0, 
         ' so the value of the SelectedIndex property cannot be used
         ' directly for casting into a TextAlign enumeration.

         ' In this example, the values of the TextAlign enumeration are 
         ' stored in the Value property of each ListItem in the 
         ' DropDownList control named List. To determine the enumeration  
         ' value, retrieve the value of the Value property, convert it to
         ' an Int32, and then cast it to a TextAlign enumeration.
         Dim EnumValue As Integer = Convert.ToInt32(List.SelectedItem.Value)

         checkboxlist1.TextAlign = CType(EnumValue, TextAlign)

      End Sub

   </script>
 
</head>

<body>
   
   <form id="form1" runat="server">
 
      <h3> CheckBoxList TextAlign 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 captions to the right or the left 
      of the check boxes.

      <table cellpadding="5">

         <tr>

            <td>

               TextAlign:

            </td>

         </tr>

         <tr>

            <td>

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

                  <asp:ListItem Value="1">Left</asp:ListItem>
                  <asp:ListItem Value="2" Selected="True">Right</asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

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

</html>

Remarques

Utilisez cette propriété pour spécifier si le texte associé aux cases à cocher s’affiche à gauche ou à droite de la case à cocher. Si cette propriété a la valeur , le texte s’affiche à droite de la case à TextAlign.Rightcocher. Si cette propriété a la valeur , le texte s’affiche à gauche de la case à TextAlign.Leftcocher.

S’applique à

Voir aussi