CheckBoxList.TextAlign プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As CheckBoxList Dim value As TextAlign value = instance.TextAlign instance.TextAlign = value
/** @property */ public TextAlign get_TextAlign () /** @property */ public void set_TextAlign (TextAlign value)
TextAlign 値の 1 つ。既定値は Right です。


このプロパティを使用して、チェック ボックスに関連付けられたテキストをチェック ボックスの左側または右側のどちらに表示するかを指定します。このプロパティを TextAlign.Right に設定すると、テキストはチェック ボックスの右側に表示されます。このプロパティを TextAlign.Left に設定すると、テキストはチェック ボックスの左側に表示されます。

TextAlign プロパティを使用して、チェック ボックスに関連付けられたテキストを CheckBoxList コントロールの右側に表示する方法のコード例を次に示します。
![]() |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。各コード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ 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>
<%@ 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>
<%@ 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>
<%@ 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 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 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="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 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 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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CheckBoxList クラス
CheckBoxList メンバ
System.Web.UI.WebControls 名前空間
TextAlign
その他の技術情報
CheckBox Web サーバー コントロールおよび CheckBoxList Web サーバー コントロール
- CheckBoxList.TextAlign プロパティのページへのリンク