HtmlTableRowCollection.CopyTo(Array, Int32) 메서드

정의

배열의 지정된 인덱스부터 시작하여 HtmlTableRowCollection의 항목을 지정된 Array에 복사합니다.

public:
 virtual void CopyTo(Array ^ array, int index);
public void CopyTo (Array array, int index);
abstract member CopyTo : Array * int -> unit
override this.CopyTo : Array * int -> unit
Public Sub CopyTo (array As Array, index As Integer)

매개 변수

array
Array

HtmlTableRowCollection에서 복사된 항목을 수신하는 0부터 시작하는 Array입니다.

index
Int32

항목을 받도록 지정된 배열의 첫째 인덱스입니다.

구현

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 CopyTo 와 같은 내용이 포함 된 배열을 만드는 메서드를는 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 Button_Click(Object sender, EventArgs e)
  {

    HtmlTableRow[] myRowArray = new HtmlTableRow[2];

    // Copy the collection to an array.
    Table1.Rows.CopyTo(myRowArray, 0);

    Span1.InnerText = "The copied items from the selected row are: ";

    // Iterate through the array and display its contents.
    foreach (HtmlTableRow row in myRowArray)
    {

      Span1.InnerText = Span1.InnerText + " " + row.Cells[0].InnerText +
                        " " + row.Cells[1].InnerText;

    }

  }

</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="Display row contents in the table"
             onserverclick = "Button_Click" 
             runat="server"/>

      <br /><br />

      <span id="Span1"
            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 myRowArray(1) As HtmlTableRow
    Dim row As HtmlTableRow
 
    ' Copy the collection to an array.
    Table1.Rows.CopyTo(myRowArray, 0)
 
    Span1.InnerText = "The copied items from the selected row are: "

    ' Iterate through the array and display its contents.
    For Each row In myRowArray
         
      Span1.InnerText = Span1.InnerText & " " & row.Cells(0).InnerText & _
                        " " & row.Cells(1).InnerText
 
    Next row

  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="Display row contents in the table"
             onserverclick = "Button_Click" 
             runat="server"/>

      <br /><br />

      <span id="Span1"
            runat="server"/>

   </form>

</body>
</html>

설명

이 메서드를 사용 하 여 내용을 복사할 합니다 HtmlTableRowCollection 지정된 된 컬렉션 System.Array 개체, 배열에 지정된 된 인덱스에서 시작 합니다.

참고

합니다 array 매개 변수는 0부터 시작 해야 합니다. System.Array합니다.

적용 대상

추가 정보