HtmlTableCellCollection Kelas

Definisi

Kumpulan HtmlTableCell objek yang mewakili sel dalam satu baris HtmlTable kontrol. Kelas ini tidak dapat diwariskan.

public ref class HtmlTableCellCollection sealed : System::Collections::ICollection
public sealed class HtmlTableCellCollection : System.Collections.ICollection
type HtmlTableCellCollection = class
    interface ICollection
    interface IEnumerable
Public NotInheritable Class HtmlTableCellCollection
Implements ICollection
Warisan
HtmlTableCellCollection
Penerapan

Contoh

Contoh kode berikut menunjukkan cara menghasilkan konten HtmlTable kontrol secara dinamis dengan menambahkan sel ke HtmlTableCellCollection koleksi. Perhatikan bahwa Cells properti baris, yang diwakili oleh HtmlTableRow objek, adalah HtmlTableCellCollection koleksi.

<%@ 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>HtmlTableCellCollection Example</title>
</head>
<body>

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

      <h3>HtmlTableCellCollection 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>HtmlTableCellCollection Example</title>
</head>
<body>

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

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

Keterangan

HtmlTableCellCollection Gunakan kelas untuk mengelola kumpulan HtmlTableCell objek secara terprogram yang mewakili sel dari satu baris dalam HtmlTable kontrol. Kelas ini biasanya digunakan untuk menambahkan, menghapus, atau memodifikasi konten sel dalam baris HtmlTable kontrol.

Catatan

Kontrol HtmlTable berisi Rows properti yang berisi kumpulan HtmlTableRow objek. Setiap HtmlTableRow objek mewakili baris individual dalam tabel. Objek HtmlTableRow berisi Cells properti yang mewakili kumpulan HtmlTableCell objek. Objek-objek ini, pada gilirannya, mewakili masing-masing sel baris. Untuk mengambil sel individual, pertama-tama dapatkan HtmlTableRow objek yang mewakili baris yang berisi sel dalam tabel (dari Rows kumpulan HtmlTable kontrol). Anda kemudian bisa mendapatkan HtmlTableCell objek yang mewakili sel dalam baris (dari Cells kumpulan HtmlTableRow objek).

Properti

Count

Mendapatkan jumlah HtmlTableCell objek dalam HtmlTableCellCollection koleksi.

IsReadOnly

Mendapatkan nilai yang menunjukkan apakah HtmlTableCellCollection koleksi bersifat baca-saja.

IsSynchronized

Mendapatkan nilai yang menunjukkan apakah akses ke koleksi disinkronkan HtmlTableCellCollection (utas aman).

Item[Int32]

HtmlTableCell Mendapatkan objek pada indeks yang ditentukan dari HtmlTableCellCollection koleksi.

SyncRoot

Mendapatkan objek yang dapat digunakan untuk menyinkronkan akses ke HtmlTableCellCollection koleksi.

Metode

Add(HtmlTableCell)

Menambahkan objek yang ditentukan HtmlTableCell ke akhir HtmlTableCellCollection koleksi.

Clear()

Menghapus semua HtmlTableCell objek dari HtmlTableCellCollection koleksi.

CopyTo(Array, Int32)

Menyalin item dari HtmlTableCellCollection koleksi ke yang ditentukan Array, dimulai dengan indeks yang ditentukan di Array.

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetEnumerator()

Mengembalikan IEnumeratorobjek -implemented yang berisi semua HtmlTableCell objek dalam HtmlTableCellCollection koleksi.

GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
Insert(Int32, HtmlTableCell)

Menambahkan objek yang ditentukan HtmlTableCell pada lokasi indeks koleksi yang HtmlTableCellCollection ditentukan.

MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
Remove(HtmlTableCell)

Menghapus objek yang ditentukan HtmlTableCell dari HtmlTableCellCollection koleksi.

RemoveAt(Int32)

HtmlTableCell Menghapus objek pada indeks yang ditentukan dari HtmlTableCellCollection koleksi.

ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Metode Ekstensi

Cast<TResult>(IEnumerable)

Mentransmisikan elemen dari IEnumerable ke jenis yang ditentukan.

OfType<TResult>(IEnumerable)

Memfilter elemen berdasarkan IEnumerable jenis tertentu.

AsParallel(IEnumerable)

Mengaktifkan paralelisasi kueri.

AsQueryable(IEnumerable)

Mengonversi menjadi IEnumerableIQueryable.

Berlaku untuk

Lihat juga