DetailsView.CellSpacing 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定儲存格之間的間距。
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 屬性來指定相鄰儲存格之間的間距量。
<%@ 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>
備註
CellSpacing使用 屬性來控制 控制項中 DetailsView 相鄰儲存格之間的間距。 此間距會垂直和水準套用。 儲存格間距是整個控制項的統一。 無法指定列或欄之間的個別儲存格間距。
注意
如果您將此屬性設定為大於 0 的值,然後將屬性設定 GridLines 為顯示儲存格框線的值,則會在相鄰儲存格的框線之間顯示間距。 在此情況下, CellSpacing 屬性會控制間距的大小。
若要調整儲存格內容與儲存格框線之間的間距,請使用 CellPadding 屬性。