다음을 통해 공유


HtmlTableRowCollection.Clear 메서드

정의

HtmlTableRow 컬렉션에서 HtmlTableRowCollection 개체를 모두 제거합니다.

public:
 void Clear();
public void Clear ();
member this.Clear : unit -> unit
Public Sub Clear ()

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 Clear 에서 모든 항목을 제거 하는 방법의 HtmlTableRowCollection 컬렉션입니다. 새 항목이 다음 컬렉션에 추가 되 고 표시 된 HtmlTable 제어 합니다.

<%@ 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 Button_Click(Object sender, EventArgs e)
  {

    // Clear the rows from the table.
    Table1.Rows.Clear();

    // Create a new table.
    // Iterate through the rows.
    for (int j = 0; j < 5; 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 < 5; 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" 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 type="button" 
             value="Create New Table"
             onserverclick="Button_Click" 
             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 Button_Click(ByVal sender As Object, ByVal e As EventArgs)
 
    Dim i As Integer
    Dim j As Integer
    Dim row As HtmlTableRow
    Dim cell As HtmlTableCell

    ' Clear the rows from the table.
    Table1.Rows.Clear()

    ' Create a new table.
    ' Iterate through the rows.
    For j = 0 To 4

      ' 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 4
            
        ' 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" 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 type="button" 
             value="Create New Table"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

설명

모두 제거 하려면이 메서드를 사용 HtmlTableRow 에서 개체를 HtmlTableRowCollection 컬렉션과 재설정 합니다 Count 속성을 0입니다.

적용 대상

추가 정보