GridView.CellSpacing 属性

定义

获取或设置单元格间的空间量。Gets or sets the amount of space between cells.

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

属性值

单元格之间的空间量(以像素为单位)。The amount of space, in pixels, between cells. 默认值为 0。The default value is 0.

示例

下面的示例演示如何使用 CellSpacing 属性以声明方式设置 GridView 控件的单元格之间的空间量。The following example demonstrates how to use the CellSpacing property to declaratively set the amount of space between the cells of a GridView control.


<%@ 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>

注解

使用 CellSpacing 属性可控制 GridView 控件中相邻单元格之间的间距。Use the CellSpacing property to control the spacing between adjacent cells in the GridView control. 此间距同时应用于垂直和水平。This spacing is applied both vertically and horizontally. 单元格间距对于整个控件是统一的。The cell spacing is uniform for the entire control. 无法指定行或列之间的个别单元格间距。Individual cell spacing between rows or columns cannot be specified.

备注

如果将此属性设置为大于0的值,然后将 GridLines 属性设置为显示单元格边框的值,则相邻单元格的边框之间将显示一个间隙。If you set this property to a value greater than 0 and then set the GridLines property to a value that displays the cell borders, a gap is displayed between the borders of adjacent cells. 在这种情况下,CellSpacing 属性控制间隙的大小。In this situation, the CellSpacing property controls the size of the gap.

适用于

另请参阅