CheckBoxList.CellPadding 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置单元格的边框和内容之间的距离(以像素为单位)。
public:
virtual property int CellPadding { int get(); void set(int value); };
[System.ComponentModel.Bindable(true)]
public virtual int CellPadding { get; set; }
public virtual int CellPadding { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.CellPadding : int with get, set
member this.CellPadding : int with get, set
Public Overridable Property CellPadding As Integer
属性值
单元格的边框和内容之间的距离(以像素为单位)。 默认值为 -1,指示未设置此属性。
- 属性
示例
下面的代码示例演示如何使用 CellPadding 属性指定控件的单元格填充为 CheckBoxList 5 像素。
注意
以下代码示例使用单文件代码模型,如果直接复制到代码隐藏文件中,可能无法正常工作。 必须将每个代码示例复制到扩展名为 .aspx 的空文本文件中。 有关 Web 窗体代码模型的详细信息,请参阅 ASP.NET Web 窗体页代码模型。
<%@ 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>
<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>
<%@ 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="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 CellPadding and CellSpacing 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 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 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"
AssociatedControlID="checkboxlist1"/>
<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="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>
注解
使用此属性可以控制单元格内容与控件中 CheckBoxList 单元格边框之间的间距。
指定的填充量将添加到具有控件中最高单元格高度和最宽单元格宽度的单元格 CheckBoxList 的所有四侧。 生成的单元格大小统一应用于控件中的所有 CheckBoxList 单元格。