CheckBoxList.CellSpacing-Eigenschaft
Ruft den Abstand (in Pixel) zwischen Zellen ab oder legt diesen fest.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Public Overridable Property CellSpacing As Integer
'Usage
Dim instance As CheckBoxList
Dim value As Integer
value = instance.CellSpacing
instance.CellSpacing = value
public virtual int CellSpacing { get; set; }
public:
virtual property int CellSpacing {
int get ();
void set (int value);
}
/** @property */
public int get_CellSpacing ()
/** @property */
public void set_CellSpacing (int value)
public function get CellSpacing () : int
public function set CellSpacing (value : int)
Eigenschaftenwert
Der Abstand (in Pixel) zwischen Zellen. Der Standardwert ist -1 und gibt an, dass diese Eigenschaft nicht festgelegt ist.
Hinweise
Mit dieser Eigenschaft steuern Sie den Abstand zwischen einzelnen Zellen im CheckBoxList-Steuerelement. Diese Eigenschaft wird sowohl vertikal als auch horizontal angewendet.
Beispiel
Das folgende Codebeispiel veranschaulicht, wie mit der CellSpacing-Eigenschaft angegeben wird, dass der Zellenabstand für das CheckBoxList-Steuerelement 5 Pixel beträgt.
Hinweis
In den folgenden Codebeispielen wird das Einzeldatei-Codemodell verwendet. Das Beispiel funktioniert möglicherweise nicht, wenn es direkt in eine CodeBehind-Datei kopiert wird. Jedes Codebeispiel muss in eine leere Textdatei mit einer ASPX-Erweiterung kopiert werden. Weitere Informationen zum Web Forms-Codemodell finden Sie unter Codemodell für ASP.NET-Webseiten.
<%@ 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 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 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>
<%@ 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 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;
}
</script>
</head>
<body>
<form 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>
Plattformen
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 unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
CheckBoxList-Klasse
CheckBoxList-Member
System.Web.UI.WebControls-Namespace
CheckBoxList.CellPadding-Eigenschaft