DetailsView.CellPadding 属性

定义

获取或设置单元格的内容和单元格的边框之间的空间量。Gets or sets the amount of space between the contents of a cell and the cell's border.

public:
 virtual property int CellPadding { int get(); void set(int value); };
public virtual int CellPadding { get; set; }
member this.CellPadding : int with get, set
Public Overridable Property CellPadding As Integer

属性值

单元格的内容和单元格的边框之间的空间量(以像素为单位)。The amount of space, in pixels, between the contents of a cell and the cell's border. 默认值为 -1,表示未设置此属性。The default value is -1, which indicates that this property is not set.

示例

下面的代码示例演示如何使用CellPadding属性来指定单元格的内容和单元格的边框之间的间距大小。The following code example demonstrates how to use the CellPadding property to specify the amount of spacing between the contents of a cell and the cell's border.


<%@ Page language="C#" %>

<!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>DetailsView CellPadding and CellSpacing Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView CellPadding and CellSpacing Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          allowpaging="true"
          cellpadding="10"
          cellspacing="5" 
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value   -->
        <!-- from the web.config file.                            -->
        <asp:SqlDataSource ID="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
          InsertCommand="INSERT INTO [Customers]([CustomerID], 
            [CompanyName], [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>


<%@ Page language="VB" %>

<!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>DetailsView CellPadding and CellSpacing Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView CellPadding and CellSpacing Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          allowpaging="true"
          cellpadding="10"
          cellspacing="5" 
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value   -->
        <!-- from the web.config file.                            -->
        <asp:SqlDataSource ID="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
          InsertCommand="INSERT INTO [Customers]([CustomerID],
            [CompanyName], [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>

注解

CellPadding使用属性可控制单元格的内容和单元格的边框之间的间距。Use the CellPadding property to control the spacing between the contents of a cell and the cell's border. 指定的填充量将添加到单元格的四个边。The padding amount specified is added to all four sides of the cell.

DetailsView控件的同一列中的所有单元格都具有相同的宽度。All cells in the same column of a DetailsView control have the same width. 填充量适用于最宽的单元格, 列中的所有其他单元格都将调整为该单元格的宽度。The padding amount is applied to the widest cell and all other cells in the column are adjusted to that cell width. 同样, 同一行中的所有单元格都具有相同的高度。Similarly, all cells in the same row have the same height. 填充量适用于行中最高的单元格, 该行中的所有其他单元格都将调整为该单元格的高度。The padding amount is applied to the tallest cell in the row and all other cells in the row are adjusted to that cell height. 无法指定单个单元大小。Individual cell sizes cannot be specified.

若要调整单元格之间的间距, CellSpacing请使用属性。To adjust the spacing between cells, use the CellSpacing property.

适用于

另请参阅