Share via


HtmlTable.Align 属性

定义

获取或设置 HtmlTable 控件相对于网页上其他元素的对齐方式。

public:
 property System::String ^ Align { System::String ^ get(); void set(System::String ^ value); };
public string Align { get; set; }
member this.Align : string with get, set
Public Property Align As String

属性值

HtmlTable 控件相对于网页上其他元素的对齐方式。 默认值为 Empty,表示未设置此属性。

示例

下面的代码示例演示如何使用 Align 属性指定控件相对于网页上其他元素的对齐方式 HtmlTable

<%@ 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>

注解

Align使用 属性指定控件相对于网页上其他元素的对齐方式HtmlTable

注意

此属性不控制控件单元格 HtmlTable 中内容的对齐方式。 若要控制单个单元格内容的对齐方式,请使用 Align 类的 HtmlTableCellVAlign 属性。 还可以通过使用 Align 类的 和 VAlign 属性 HtmlTableRow 来控制整行中单元格内容的对齐方式。

下表列出了可用于此属性的值。

“值” 说明
Left HtmlTable 控件对齐在网页的左边缘。
Center HtmlTable 控件对齐在网页中间。
Right HtmlTable 控件对齐在网页的右边缘。

注意

如果指定 LeftRight 对齐,则网页上的其他元素将分别环绕到控件的 HtmlTable 右侧或左侧。 如果指定 Center 对齐方式,则不会发生包装,并且控件下方会显示其他元素。

适用于

另请参阅