CheckBoxList
.
.
::
.RepeatColumns 属性
Public Overridable Property RepeatColumns As Integer
Visual Basic(用法)
Dim instance As CheckBoxList Dim value As Integer value = instance.RepeatColumns instance.RepeatColumns = value
C#
public virtual int RepeatColumns { get; set; }
Visual C++
public: virtual property int RepeatColumns { int get (); void set (int value); }
J#
/** @property */ public int get_RepeatColumns() /** @property */ public void set_RepeatColumns(int value)
JScript
public function get RepeatColumns () : int public function set RepeatColumns (value : int)
ASP.NET
<asp:CheckBoxList RepeatColumns="Int32" />
属性值
类型: System..::.Int32要在 CheckBoxList 控件中显示的列数。默认值为 0,表示未设置该属性。

异常 | 条件 |
---|---|
ArgumentOutOfRangeException | 列数设置为负值。 |

使用该属性指定显示 CheckBoxList 控件项的列数。如果未设置该属性,则 CheckBoxList 控件在一个列中显示所有列表项。

下面的代码示例演示如何使用 RepeatColumns 属性指定在 CheckBoxList 控件中显示两列。
![]() |
---|
下面的代码示例使用单文件代码模型;在将这些代码示例直接复制到代码隐藏文件中时,它们可能无法正常工作。必须将每个代码示例都复制到具有 .aspx 扩展名的空文本文件中。有关 Web 窗体代码模型的更多信息,请参见 ASP.NET 网页代码模型。 |
Visual Basic
<%@ 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 > <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>
C#
<%@ 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 > <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>
JScript
<%@ Page Language="JScript" AutoEventWireup="True" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head> <title>CheckBoxList Example</title> <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 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>
Visual Basic
<%@ 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 > <head runat="server"> <title> CheckBoxList RepeatColumns 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 number columns in the CheckBoxList control. checkboxlist1.RepeatColumns = List.SelectedIndex End Sub </script> </head> <body> <form id="form1" 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" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head runat="server"> <title> CheckBoxList RepeatColumns 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 number columns in the CheckBoxList control. checkboxlist1.RepeatColumns = List.SelectedIndex; } </script> </head> <body> <form id="form1" 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>