HtmlTableRow 服务器控件声明性语法

[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]

创建一个服务器端控件,该控件映射到 <tr> HTML 元素并允许您创建和操作表中的行。

<tr 
    EnableViewState="False|True"
    Id="string"
    Visible="False|True"
    OnDataBinding="OnDataBinding event handler"
    OnDisposed="OnDisposed event handler"
    OnInit="OnInit event handler"
    OnLoad="OnLoad event handler"
    OnPreRender="OnPreRender event handler"
    OnUnload="OnUnload event handler"
    runat="server"
    >
 
   <td>cellcontent</td> 
   <td>cellcontent</td> 
   <td>cellcontent</td> 
 
</tr>

备注

使用 HtmlTableRow 类对 <tr> HTML 元素进行编程。 <tr> 元素表示表中的行。

HtmlTableRow 类使您可以控制表中各个独立行的外观。 通过设置 BgColorBorderColorHeight 属性,可以分别控制行的背景色、边框颜色和高度。

通过设置 AlignVAlign 属性,分别控制行中单元格内容的水平和垂直对齐方式。

表中的每行都包含一个 Cells 集合,该集合对于该行中的每个单元格都包含一个 HtmlTableCell

示例

下面的示例演示如何使用 HtmlTableCell 修改 HtmlTable 控件中的单元格的内容。

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

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>
<title>HtmlTableRow Control</title>

   <script runat="server">
       Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)

           Dim i As Integer
           Dim j As Integer

           ' Iterate through the rows of the table.
           For i = 0 To Table1.Rows.Count - 1

               ' Iterate through the cells of a row.       
               For j = 0 To Table1.Rows(i).Cells.Count - 1

                   ' Change the inner HTML of the cell.
                   Table1.Rows(i).Cells(j).InnerHtml = "Row " & i.ToString() _
                                                       & ", Column " & _
                                                       j.ToString()
               Next j

           Next i
       End Sub
   </script>

</head>
<body>

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

      <h3>HtmlTableCell Example</h3>

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

         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
         </tr>
         <tr>
            <td>
               Cell 3
            </td>
            <td>
               Cell 4
            </td>
         </tr>

      </table>


      <br /><br />

      <input id="Button1" type="button" 
             value="Change Table Contents"
              onserverclick="Button_Click" 
             runat="server"/>
   </form>
</body>
</html>
<%@ 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">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>
<title>HtmlTableRow Control</title>

   <script runat="server">
      void Button_Click(Object sender, EventArgs e) 
      {

         // Iterate through the rows of the table.
         for (int i=0; i<=Table1.Rows.Count - 1; i++)
         {

            // Iterate through the cells of a row.
            for (int j=0; j<=Table1.Rows[i].Cells.Count - 1; j++)
            {
               // Change the inner HTML of the cell.
               Table1.Rows[i].Cells[j].InnerHtml = "Row " + i.ToString() + 
                                                   ", Column " + 
                                                   j.ToString(); 
            }

         }

      }
   </script>

</head>
<body>

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

      <h3>HtmlTableCell Example</h3>

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

         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
         </tr>

         <tr>
            <td>
               Cell 3
            </td>
            <td>
               Cell 4
            </td>
         </tr>

      </table>


      <br /><br />

      <input id="Button1" type="button" 
             value="Change Table Contents"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>
</body>
</html>

请参见

参考

HtmlTableRow

HtmlTableCell 服务器控件声明性语法

HtmlTable 服务器控件声明性语法

System.Web.UI.HtmlControls

其他资源

HTML 服务器控件