GridView.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

Значение свойства

Расстояние от содержимого ячейки до ее границ (в пикселях). По умолчанию используется значение -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>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 свойство для расстояния между содержимым ячейки и ее границей. Указанная сумма заполнений добавляется ко всем четырем сторонам ячейки.

Все ячейки в одном столбце элемента управления имеют одинаковую GridView ширину. Размер заполнений применяется к самой широкой ячейке, а все остальные ячейки в столбце имеют эту ширину ячейки. Аналогичным образом, все ячейки в одной строке имеют одинаковую высоту. Размер заполнений применяется к самой высокой ячейке в строке, а все остальные ячейки в строке имеют эту высоту. Отдельные размеры ячеек указать нельзя.

Применяется к

См. также раздел