DetailsView.CellPadding 屬性

定義

取得或設定儲存格內容和其框線之間的間距。

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

屬性值

Int32

儲存格內容和其框線之間的間距數 (以像素為單位)。 預設值為 -1,表示這個屬性未設定。

範例

下列程式碼範例示範如何使用 CellPadding 屬性來指定儲存格內容與儲存格框線之間的間距量。


<%@ 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使用 屬性來控制儲存格內容與儲存格框線之間的間距。 指定的填補量會新增至儲存格的所有四邊。

控制項相同資料行 DetailsView 中的所有儲存格都有相同的寬度。 填補量會套用至最寬的儲存格,而資料行中的所有其他儲存格都會調整為該儲存格寬度。 同樣地,相同資料列中的所有儲存格都有相同的高度。 填補量會套用至資料列中最高的儲存格,而資料列中所有其他儲存格都會調整為該儲存格高度。 無法指定個別儲存格大小。

若要調整儲存格之間的間距,請使用 CellSpacing 屬性。

適用於

另請參閱