CheckBoxList.CellSpacing Property
Gets or sets the distance (in pixels) between cells.
Assembly: System.Web (in System.Web.dll)
Property Value
Type: System.Int32The distance (in pixels) between cells. The default is -1, which indicates that this property is not set.
Use this property to control the spacing between individual cells in the CheckBoxList control. This property is applied both vertically and horizontally.
The following code example demonstrates how to use the CellSpacing property to specify that the cell spacing for the CheckBoxList control is 5 pixels.
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="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="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 CellPadding and CellSpacing 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 cell padding and cell spacing based on the selection ' from the drop down-list controls. Notice that cell padding and ' cell spacing only applies when the RepeatLayout property is set ' to RepeatLayout.Table. checkboxlist1.CellPadding = CellPaddingList.SelectedIndex checkboxlist1.CellSpacing = CellSpacingList.SelectedIndex End Sub </script> </head> <body> <form id="form1" runat="server"> <h3> CheckBoxList CellPadding and CellSpacing 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 different values for the cell padding and cell spacing. <table cellpadding="5"> <tr> <td> CellPadding: </td> <td> CellSpacing: </td> </tr> <tr> <td> <asp:DropDownList id="CellPaddingList" AutoPostBack="True" OnSelectedIndexChanged="Index_Change" runat="server"> <asp:ListItem>0</asp:ListItem> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> <asp:ListItem Selected="True">5</asp:ListItem> </asp:DropDownList> </td> <td> <asp:DropDownList id="CellSpacingList" AutoPostBack="True" OnSelectedIndexChanged="Index_Change" runat="server"> <asp:ListItem>0</asp:ListItem> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> <asp:ListItem Selected="True">5</asp:ListItem> </asp:DropDownList> </td> </tr> </table> </form> </body> </html>
Available since 1.1
