Freigeben über


TableRow Web Server Control

Represents a row in the Table control and allows you to manipulate it programmatically.

<asp:TableRow id="TableRow1"
     HorizontalAlign="Center|Justify|Left|NotSet|Right"
     VerticalAlign="Bottom|Middle|NotSet|Top"
     runat="server">

   <asp:TableCell>
      Cell text
   </asp:TableCell>

</asp:TableRow>

Remarks

An instance of the TableRow class represents a row in a Table control. The rows of a table are stored in the Rows collection of the Table control.

This class allows you to control how the contents of the row are displayed. Setting the HorizontalAlign and VerticalAlign properties specify the horizontal and vertical alignments of the contents in the row, respectively.

The cells of a row (represented by instances of the TableCell class) are stored in the Cells collection of the TableRow representing the row. You can programmatically manage the cells in the row by using the Cells collection.

For detailed information on the TableRow Web server control's properties and events, see the TableRow Class documentation.

Example

The following example demonstrates how to use a TableRow object to add a row to a Table control.

<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
   <script runat="server">
      Sub Page_Load(sender As Object, e As EventArgs)
         ' Generate rows and cells.           
         Dim numrows As Integer = 3
         Dim numcells As Integer = 2
         Dim j As Integer
         For j = 0 To numrows - 1
            Dim r As New TableRow()
            Dim i As Integer
            For i = 0 To numcells - 1
               Dim c As New TableCell()
               c.Controls.Add(New LiteralControl("row " & j.ToString() & _
                              ", cell " & i.ToString()))
               r.Cells.Add(c)
            Next i
            Table1.Rows.Add(r)
         Next j
      End Sub 'Page_Load
   </script>
</head>
<body>
   <form runat="server">
      <h3>TableRow Example</h3>
      <asp:Table id="Table1" 
           Font-Name="Verdana" 
           Font-Size="8pt" 
           CellPadding="5" 
           CellSpacing="0"           
           BorderWidth="1" 
           Gridlines="Both" 
           runat="server"/>
   </form>
</body>
</html>
[C#]
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
   <script runat="server">
      void Page_Load(Object sender, EventArgs e) 
      {
         // Generate rows and cells.           
         int numrows = 3;
         int numcells = 2;
         for (int j=0; j<numrows; j++) 
         {          
            TableRow r = new TableRow();
            for (int i=0; i<numcells; i++) 
            {
               TableCell c = new TableCell();
               c.Controls.Add(new LiteralControl("row " + j.ToString() +
                              ", cell " + i.ToString()));
               r.Cells.Add(c);
            }
            Table1.Rows.Add(r);
         }
      }
   </script>
</head>
<body>
   <form runat="server">
      <h3>TableRow Example</h3>
      <asp:Table id="Table1" 
           GridLines="Both" 
           HorizontalAlign="Center" 
           Font-Name="Verdana" 
           Font-Size="8pt" 
           CellPadding="15" 
           CellSpacing="0" 
           runat="server"/>
   </form>
</body>
</html> 

See Also

Web Server Controls | HtmlTableRow Class