GridView.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 example demonstrates how to use the CellPadding property to declaratively set the amount of space 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>GridView CellPadding and CellSpacing Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView CellPadding and CellSpacing Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        cellpadding="10"
        cellspacing="5"
        runat="server">
                
      </asp:gridview>
            
      <!-- 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="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
        
    </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>GridView CellPadding and CellSpacing Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView CellPadding and CellSpacing Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        cellpadding="10"
        cellspacing="5"
        runat="server">
                
      </asp:gridview>
            
      <!-- 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="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
        
    </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.

GridView 控件的同一列中的所有单元格都具有相同的宽度。All cells in the same column of a GridView control have the same width. 填充量适用于最宽的单元格,列中的所有其他单元格都具有此单元格的宽度。The padding amount is applied to the widest cell and all other cells in the column have this 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 have this cell height. 无法指定单个单元大小。Individual cell sizes cannot be specified.

适用于

另请参阅