GridView.CellSpacing 属性

定义

获取或设置单元格间的空间量。

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

属性值

单元格之间的空间量(以像素为单位)。 默认值为 0。

示例

以下示例演示如何使用 CellSpacing 属性以声明方式设置控件单元格 GridView 之间的空间量。


<%@ 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相邻单元格之间的间距。 此间距同时以垂直和水平方式应用。 整个控件的单元格间距是统一的。 无法指定行或列之间的单个单元格间距。

注意

如果将此属性设置为大于 0 的值,然后将该属性设置为 GridLines 显示单元格边框的值,则会在相邻单元格的边框之间显示一个间距。 在这种情况下, CellSpacing 属性控制间隙的大小。

适用于

另请参阅