語言

HtmlTableRowCollection 類別

定義

一組 HtmlTableRow 代表控制列 HtmlTable 的物件。 此類別無法獲得繼承。

public ref class HtmlTableRowCollection sealed : System::Collections::ICollection
public sealed class HtmlTableRowCollection : System.Collections.ICollection
type HtmlTableRowCollection = class
    interface ICollection
    interface IEnumerable
Public NotInheritable Class HtmlTableRowCollection
Implements ICollection
繼承
HtmlTableRowCollection
實作

範例

以下程式碼範例示範如何透過向集合加入列HtmlTable來動態產生控制項的內容HtmlTableRowCollection。 請注意 Rows ,表的屬性是物件 HtmlTableRowCollection 。

<%@ 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 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 Cells collection.
         HtmlTableCell cell = new HtmlTableCell();
         cell.Controls.Add(new LiteralControl("row " +
                           j.ToString() +
                           ", cell " +
                           i.ToString()));
         row.Cells.Add(cell);
       }
       Table1.Rows.Add(row);
     }
   }

</script>

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

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

      <h3>HtmlTableRowCollection Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black; padding:5"
             cellspacing="0"
             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>

        

      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="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 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 and add it to the Rows collection.
      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 Cells collection.
        cell = New HtmlTableCell()
        cell.Controls.Add(New LiteralControl("row " & _
                                          j.ToString() & _
                                          ", cell " & _
                                          i.ToString()))
        row.Cells.Add(cell)
            
      Next i

      Table1.Rows.Add(row)
         
    Next j
      
  End Sub

</script>

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

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

      <h3>HtmlTableRowCollection Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black; padding:5"
             cellspacing="0"
             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>

        

      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>

備註

使用該 HtmlTableRowCollection 類別來程式化管理一組 HtmlTableRow 代表控制列 HtmlTable 的物件。 此類別通常用於新增、移除或修改控制項中 HtmlTable 某一列的內容。

Note

HtmlTable控制項包含Rows一個屬性,代表一組HtmlTableRow物件。 每個 HtmlTableRow 欄位代表表格中的一列。 An HtmlTableRow 包含 Cells 一個代表一組 HtmlTableCell 物件的屬性。 這些物件又代表表格中的各個單元格。 要取得單一儲存格,首先從控制集合HtmlTableRow中取得Rows代表該儲存格HtmlTable列的物件。 接著你可以從 HtmlTableCell 的集合Cells中取得HtmlTableRow代表該列格子的物件。

屬性

名稱 Description
Count

取得集合中的HtmlTableRow物件數量HtmlTableRowCollection。

IsReadOnly

會獲得一個值,表示該 HtmlTableRowCollection 集合是否為唯讀。

IsSynchronized

會獲得一個值,表示存取 HtmlTableRowCollection 集合是否同步(執行緒安全)。

Item[Int32]

從集合中取得 HtmlTableRow 指定索引 HtmlTableRowCollection 的物件。

SyncRoot

取得可用來同步存取 HtmlTableRowCollection 集合的物件。

方法

名稱 Description
Add(HtmlTableRow)

將指定的 HtmlTableRow 物件附加到集合的 HtmlTableRowCollection 末尾。

Clear()

移除收藏中HtmlTableRow的所有HtmlTableRowCollection物件。

CopyTo(Array, Int32)

從 HtmlTableRowCollection 集合中複製項目到指定 Array 物件,從陣列中指定的索引開始。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEnumerator()

回傳一個IEnumerator包含集合中HtmlTableRow所有HtmlTableRowCollection物件的 -實作物件。

GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type。

(繼承來源 Object)
Insert(Int32, HtmlTableRow)

將 HtmlTableRow 物件加入集合中指定的位置。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
Remove(HtmlTableRow)

從集合中移除指定的 HtmlTableRow 物件 HtmlTableRowCollection 。

RemoveAt(Int32)

從集合中移除 HtmlTableRow 指定索引 HtmlTableRowCollection 的物件。

ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

擴充方法

名稱 Description
AsParallel(IEnumerable)

啟用查詢的平行處理。

AsQueryable(IEnumerable)

將 IEnumerable 轉換成 IQueryable。

Cast<TResult>(IEnumerable)

將 IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別篩選 IEnumerable 的專案。

適用於

另請參閱