Freigeben über


HtmlTable.Rows-Eigenschaft

Ruft eine HtmlTableRowCollection-Auflistung ab, die alle Zeilen im HtmlTable-Steuerelement enthält.

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)

Syntax

'Declaration
Public Overridable ReadOnly Property Rows As HtmlTableRowCollection
'Usage
Dim instance As HtmlTable
Dim value As HtmlTableRowCollection

value = instance.Rows
public virtual HtmlTableRowCollection Rows { get; }
public:
virtual property HtmlTableRowCollection^ Rows {
    HtmlTableRowCollection^ get ();
}
/** @property */
public HtmlTableRowCollection get_Rows ()
public function get Rows () : HtmlTableRowCollection

Eigenschaftenwert

Eine HtmlTableRowCollection, die alle Zeilen im HtmlTable-Steuerelement enthält.

Hinweise

Mit der Rows-Auflistung können Sie programmgesteuert auf die Zeilen im HtmlTable-Steuerelement zugreifen. Sie können der Auflistung programmgesteuert Zeilen hinzufügen sowie Zeilen programmgesteuert in die Auflistung einfügen und aus dieser entfernen.

Hinweis

Wenn keine <tr>-Elemente im HtmlTable-Steuerelement aufgelistet sind, wird ein leeres HtmlTableRowCollection-Objekt zurückgegeben.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie dem HtmlTable-Steuerelement mit der Rows-Auflistung programmgesteuert eine Zeile hinzugefügt wird.

<%@ Page Language="VB" %>

<script runat="server">

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

    Dim i As Integer
    Dim j As Integer
    Dim row As HtmlTableRow
    Dim cell As HtmlTableCell

    ' Get the number of rows and columns selected by the user.
    Dim numrows As Integer = CInt(Select1.Value)
    Dim numcells As Integer = CInt(Select2.Value)

    ' Iterate through the rows.
    For j = 0 To numrows - 1

      ' Create a new row.
      row = New HtmlTableRow()

      ' Provide a different background color for alternating rows.
      If (j Mod 2) = 1 Then
        row.BgColor = "Gray"
      End If

      ' Iterate through the cells of a row.
      For i = 0 To numcells - 1
        
        ' Create a new cell and add it to the HtmlTableRow
        ' Cells collection.
        cell = New HtmlTableCell()
        cell.Controls.Add(New LiteralControl("row " & _
                                          j.ToString() & _
                                          ", cell " & _
                                          i.ToString()))
        row.Cells.Add(cell)
            
      Next i

      ' Add the row to the HtmlTable Rows collection.
      Table1.Rows.Add(row)
         
    Next j
      
  End Sub

</script>

<html>
<head>
   <title>HtmlTable Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTable Example</h3>

      <table id="Table1" 
             CellPadding="5" 
             CellSpacing="0" 
             Border="1" 
             BorderColor="black" 
             runat="server"/>
        
      <hr>

      Select the number of rows and columns to create: <br><br>

      Table rows:
      <select id="Select1" 
              runat="server">

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

      &nbsp;&nbsp;

      Table cells:
      <select id="Select2" 
              runat="server">

         <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="submit" 
             value="Generate Table" 
             runat="server"/>

   </form>

</body>
</html>
<%@ Page Language="C#" %>

<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {

    // Get the number of rows and columns selected by the user.
    int numrows = Convert.ToInt32(Select1.Value);
    int numcells = Convert.ToInt32(Select2.Value);

    // Iterate through the rows.
    for (int j = 0; j < numrows; j++)
    {

      // Create a new row and add it to the Rows collection.
      HtmlTableRow row = new HtmlTableRow();

      // Provide a different background color for alternating rows.
      if (j % 2 == 1)
        row.BgColor = "Gray";

      // Iterate through the cells of a row.
      for (int i = 0; i < numcells; i++)
      {
        // Create a new cell and add it to the HtmlTableRow 
        // Cells collection.
        HtmlTableCell cell = new HtmlTableCell();
        cell.Controls.Add(new LiteralControl("row " +
                          j.ToString() +
                          ", cell " +
                          i.ToString()));
        row.Cells.Add(cell);
      }

      // Add the row to the HtmlTable Rows collection.
      Table1.Rows.Add(row);
    }
  }

</script>

<html>
<head>
   <title>HtmlTable Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTable Example</h3>

      <table id="Table1" 
             CellPadding="5" 
             CellSpacing="0" 
             Border="1" 
             BorderColor="black" 
             runat="server"/>
        
      <hr>

      Select the number of rows and columns to create: <br><br>

      Table rows:
      <select id="Select1" 
              runat="server">

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

      &nbsp;&nbsp;

      Table cells:
      <select id="Select2" 
              runat="server">

         <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="submit" 
             value="Generate Table" 
             runat="server"/>

   </form>

</body>
</html>
<%@ Page Language="JScript" %>

<script runat="server">

  function Page_Load(sender : Object, e : EventArgs) 
  {

    // Get the number of rows and columns selected by the user.
    var numrows : int = Convert.ToInt32(Select1.Value);
    var numcells : int = Convert.ToInt32(Select2.Value);

    // Iterate through the rows.
    for (var j : int = 0; j < numrows; j++) 
    {

      // Create a new row and add it to the Rows collection.
      var row : HtmlTableRow = new HtmlTableRow();

      // Provide a different background color for alternating rows.
      if (j%2 == 1)
        row.BgColor="Gray";

      // Iterate through the cells of a row.
      for (var i : int = 0; i < numcells; i++) 
      {
        // Create a new cell and add it to the HtmlTableRow 
        // Cells collection.
        var cell : HtmlTableCell = new HtmlTableCell();
        cell.Controls.Add(new LiteralControl("row " + 
                      j.ToString() + 
                      ", cell " +
                     i.ToString()));
        row.Cells.Add(cell);
      }
      
      // Add the row to the HtmlTable Rows collection.
      Table1.Rows.Add(row);
    }
  }

</script>

<html>
<head>
   <title>HtmlTable Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTable Example</h3>

      <table id="Table1" 
             CellPadding="5" 
             CellSpacing="0" 
             Border="1" 
             BorderColor="black" 
             runat="server"/>
        
      <hr>

      Select the number of rows and columns to create: <br><br>

      Table rows:
      <select id="Select1" 
              runat="server">

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

      &nbsp;&nbsp;

      Table cells:
      <select id="Select2" 
              runat="server">

         <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="submit" 
             value="Generate Table" 
             runat="server"/>

   </form>

</body>
</html>

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

HtmlTable-Klasse
HtmlTable-Member
System.Web.UI.HtmlControls-Namespace
HtmlTableRowCollection

Weitere Ressourcen

HTML-Serversteuerelemente