HtmlTable.CellPadding Propiedad

Definición

Obtiene o establece la cantidad de espacio (en píxeles) entre el contenido de una celda y el borde de la misma en el control HtmlTable.

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

Valor de propiedad

Cantidad de espacio (en píxeles) entre el contenido de una celda y su borde en el control HtmlTable. El valor predeterminado es -1, que indica que no se ha establecido esta propiedad.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la CellPadding propiedad para controlar mediante programación el espaciado entre el contenido de la celda y el borde de la celda en el HtmlTable control .

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Button_Click(Object sender, EventArgs e)
  {

    // Set the HtmlTable properties according to the
    // user selections.
    Table1.CellSpacing = Convert.ToInt32(SpacingSelect.Value);
    Table1.CellPadding = Convert.ToInt32(PaddingSelect.Value);
    Table1.Align = AlignSelect.Value;

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTable Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTable Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black"
             runat="server">

         <tr>
            <th>
               Column 1
            </th>
            <th>
               Column 2
            </th>
            <th>
               Column 3
            </th>
         </tr>
         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
            <td>
               Cell 3
            </td>
         </tr>
         <tr>
            <td>
               Cell 4
            </td>
            <td>
               Cell 5
            </td>
            <td>
               Cell 6
            </td>
         </tr>

      </table>
      
      <br /><br /><br /><br /><br /><br /><br /><br />
      
      <hr />

      Select the display settings: <br /><br />

      Align:
      <select id="AlignSelect" 
              runat="server">

         <option value="Left">Left</option>
         <option value="Center">Center</option>
         <option value="Right">Right</option>
        
      </select>

        

      CellPadding:
      <select id="PaddingSelect" 
              runat="server">

         <option value="0">0</option>
         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>

      </select>

        

      CellSpacing:
      <select id="SpacingSelect" 
              runat="server">

         <option value="0">0</option>
         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>

      </select>
       
      <br /><br />
  
      <input type="button" 
             value="Generate Table"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>

</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)

    ' Set the HtmlTable properties according to the
    ' user selections.
    Table1.CellSpacing = CInt(SpacingSelect.Value)
    Table1.CellPadding = CInt(PaddingSelect.Value)
    Table1.Align = AlignSelect.Value

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTable Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTable Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black"
             runat="server">

         <tr>
            <th>
               Column 1
            </th>
            <th>
               Column 2
            </th>
            <th>
               Column 3
            </th>
         </tr>
         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
            <td>
               Cell 3
            </td>
         </tr>
         <tr>
            <td>
               Cell 4
            </td>
            <td>
               Cell 5
            </td>
            <td>
               Cell 6
            </td>
         </tr>

      </table>
      
      <br /><br /><br /><br /><br /><br /><br /><br />
      
      <hr />

      Select the display settings: <br /><br />

      Align:
      <select id="AlignSelect" 
              runat="server">

         <option value="Left">Left</option>
         <option value="Center">Center</option>
         <option value="Right">Right</option>
        
      </select>

        

      CellPadding:
      <select id="PaddingSelect" 
              runat="server">

         <option value="0">0</option>
         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>

      </select>

        

      CellSpacing:
      <select id="SpacingSelect" 
              runat="server">

         <option value="0">0</option>
         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>

      </select>
       
      <br /><br />
  
      <input type="button" 
             value="Generate Table"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

Comentarios

Utilice la CellPadding propiedad para controlar el espaciado entre el contenido de una celda y el borde de la celda. La cantidad de relleno especificada se agrega a los cuatro lados de la celda. Todas las celdas de una columna comparten el mismo ancho de celda; por lo tanto, el espaciado se aplica a la celda más ancha de la columna. De forma similar, todas las celdas de la misma fila comparten el mismo alto de celda. El espaciado se aplica a la celda más alta de la fila. No se pueden especificar tamaños de celda individuales.

Se aplica a

Consulte también