Calendar.CellPadding 属性  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置单元格的内容和单元格的边框之间的空间量。
public:
 property int CellPadding { int get(); void set(int value); };[System.ComponentModel.Bindable(true)]
public int CellPadding { get; set; }public int CellPadding { get; set; }[<System.ComponentModel.Bindable(true)>]
member this.CellPadding : int with get, setmember this.CellPadding : int with get, setPublic Property CellPadding As Integer属性值
单元格的内容和单元格的边框之间的空间量(以像素为单位)。 默认值是 2。
- 属性
例外
指定的单元格填充量小于 -1。
示例
下面的代码示例演示如何使用 CellPadding 属性填充每个 5 像素的单元格。
<%@ 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>Calendar Example</title>
</head>
<body>
   <form id="form1" runat="server">
      <h3>Calendar Example</h3>
      <asp:Calendar id="calendar1" runat="server"
           CellPadding="5"
           ShowGridLines="true"/>
            
   </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>Calendar Example</title>
</head>
<body>
   <form id="form1" runat="server">
      <h3>Calendar Example</h3>
      <asp:Calendar id="calendar1" runat="server"
           CellPadding="5"
           ShowGridLines="true"/>
            
   </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" >
   <script runat="server" >
  
      void Selection_Change(Object sender, EventArgs e)
      {
         // Set the cell padding and cell spacing for the Calendar control
         // based on the values selected from the DropDownList control.
         Calendar1.CellPadding = CellPaddingList.SelectedIndex;
         Calendar1.CellSpacing = CellSpacingList.SelectedIndex;
      }
  
   </script>
  
<head runat="server">
    <title> Calendar CellPadding and CellSpacing Example </title>
</head>
<body>
   <form id="form1" runat="server">
  
      <h3> Calendar CellPadding and CellSpacing Example </h3>
      Select the cell padding and cell spacing values.
      <br /><br /> 
  
      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>
      <br /><br />
      <table cellpadding="5">
         <tr>
            <td>
               Cell padding:
            </td>
            <td>
               Cell spacing:
            </td>
         </tr>
         <tr>
            <td>
               <asp:DropDownList id="CellPaddingList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_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:ListItem> 4 </asp:ListItem>
                  <asp:ListItem> 5 </asp:ListItem>
               </asp:DropDownList>
            </td>
            <td>
               <asp:DropDownList id="CellSpacingList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">
                  <asp:ListItem Selected="True"> 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> 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" >
   <script runat="server" >
  
      Sub Selection_Change(sender As Object, e As EventArgs)
         ' Set the cell padding and cell spacing for the Calendar control
         ' based on the values selected from the DropDownList control.
         Calendar1.CellPadding = CellPaddingList.SelectedIndex
         Calendar1.CellSpacing = CellSpacingList.SelectedIndex
      End Sub
  
   </script>
  
<head runat="server">
    <title> Calendar CellPadding and CellSpacing Example </title>
</head>
<body>
   <form id="form1" runat="server">
  
      <h3> Calendar CellPadding and CellSpacing Example </h3>
      Select the cell padding and cell spacing values.
      <br /><br /> 
  
      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>
      <br /><br />
      <table cellpadding="5">
         <tr>
            <td>
               Cell padding:
            </td>
            <td>
               Cell spacing:
            </td>
         </tr>
         <tr>
            <td>
               <asp:DropDownList id="CellPaddingList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_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:ListItem> 4 </asp:ListItem>
                  <asp:ListItem> 5 </asp:ListItem>
               </asp:DropDownList>
            </td>
            <td>
               <asp:DropDownList id="CellSpacingList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">
                  <asp:ListItem Selected="True"> 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> 5 </asp:ListItem>
               </asp:DropDownList>
            </td>
         </tr>
  
      </table>
  
   </form>
</body>
</html>
注解
使用此属性可控制单元格内容与单元格边框之间的间距。 指定的填充量将添加到单元格的所有四侧。 无法指定单个单元格大小。
注意
将此属性设置为 -1 表示未在呈现的表中设置此属性。