CheckBoxList.RepeatLayout Property
Gets or sets a value that specifies whether the list will be rendered by using a table element, a ul element, an ol element, or a span element.
Assembly: System.Web (in System.Web.dll)
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The specified layout is not one of the RepeatLayout values. |
For information about the available options, see the RepeatLayout enumeration.
Note |
|---|
Two options are new as of ASP.NET 4: OrderedList and UnorderedList. |
Some RepeatLayout settings do not allow horizontal layout. For more information, see the RepeatLayout enumeration.
The following code example demonstrates how to use the RepeatLayout property to change the HTML that the CheckBoxList control renders.
Note |
|---|
The following code samples use the single-file code model and may not work correctly if copied directly into a code-behind file. Each code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model. |
<%@ 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>
Available since 1.1
