다음을 통해 공유


TableCellCollection.CopyTo(Array, Int32) 메서드

정의

TableCellCollection의 지정된 인덱스에서 시작하여 Array에서 지정된 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

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

index
Int32

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

구현

예제

다음 예제에서는 사용 CopyTo 하는 방법에 설명 합니다 에서 항목을 TableCellCollection 복사 하는 메서드를 지정 된 배열입니다.

<%@ Page Language="C#" %>

<!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) 
    {
        int numrows = 5;
        int numcells = 6;
        int counter = 1;
        ArrayList a_row = new ArrayList();

        // Create a table.
        for (int rowNum = 0; rowNum < numrows; rowNum++) 
        {          
            TableRow rw = new TableRow();
            for (int cellNum = 0; cellNum < numcells; cellNum++) 
            {
                TableCell cel = new TableCell();
                cel.Text=counter.ToString();
                rw.Cells.Add(cel);
                counter++;
            }
            Table1.Rows.Add(rw);
        }

        if (!IsPostBack) 
        {
            // Create a DropDownList for the number of rows.
            for (int rowNum = 0; rowNum < numrows; rowNum++) 
            {
                a_row.Add(rowNum.ToString());
            }

            List1.DataSource = a_row; 
            List1.DataBind();
        }
    }

    void Button_Click(object sender, EventArgs e) 
    {
        int row = List1.SelectedIndex;
        TableCell[] myCellArray = new TableCell[6];
 
        // Copy the collection to an array.
        Table1.Rows[row].Cells.CopyTo(myCellArray, 0);      
 
        Label1.Text = "The copied items from the selected row are: ";

        // Iterate through the array and display its contents.
        foreach (TableCell cel in myCellArray) 
        {
            Label1.Text = Label1.Text + " " + cel.Text;
        }
    }
 
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>TableCellCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>TableCellCollection Example</h3>
    <asp:Table id="Table1" 
        GridLines="Both" 
        HorizontalAlign="Center" 
        Font-Names="Verdana" 
        Font-Size="8pt" 
        CellPadding="15" 
        CellSpacing="0" 
        runat="server" />

        <p style="text-align:center">Select a row:
            <br />&nbsp;<br />
            Row: <asp:DropDownList id="List1" 
            runat="server" />
 
            <br /><br />
            <asp:Button id="Button1"
                Text="Copy Row to Array"
                OnClick="Button_Click"
                runat="server" />
            <br /><br />
            <asp:Label id="Label1"
                runat="server" />
       </p>
 
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!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(sender As Object, e As EventArgs)
        Dim numrows As Integer = 5
        Dim numcells As Integer = 6
        Dim counter As Integer = 1
        Dim a_row As New ArrayList()
            
        ' Create a table.
        Dim rowNum As Integer
        For rowNum = 0 To numrows - 1
            Dim rw As New TableRow()
            Dim cellNum As Integer
            For cellNum = 0 To numcells - 1
                Dim cel As New TableCell()
                cel.Text = counter.ToString()
                rw.Cells.Add(cel)
                counter += 1
            Next
            Table1.Rows.Add(rw)
        Next

        If Not IsPostBack Then
            ' Create a DropDownList for the number of rows.
            For rowNum = 0 To numrows - 1
                a_row.Add(rowNum.ToString())
            Next

            List1.DataSource = a_row
            List1.DataBind()
        End If 
    End Sub

    Sub Button_Click(sender As Object, e As EventArgs)
        Dim row As Integer = List1.SelectedIndex
        Dim myCellArray(6) As TableCell

        ' Copy the collection to an array.
        Table1.Rows(row).Cells.CopyTo(myCellArray, 0)

        Label1.Text = "The copied items from the selected row are: "

        ' Iterate through the array and display its contents.
        Dim cel As TableCell
        For Each cel In  myCellArray
            Label1.Text = Label1.Text & " " & cel.Text
                
        Next
    End Sub
 
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>TableCellCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>TableCellCollection Example</h3>
    <asp:Table id="Table1" 
        GridLines="Both" 
        HorizontalAlign="Center" 
        Font-Names="Verdana" 
        Font-Size="8pt" 
        CellPadding="15" 
        CellSpacing="0" 
        runat="server" />

        <p style="text-align:center">Select a row:
            <br />&nbsp;<br />
            Row: <asp:DropDownList id="List1" 
            runat="server" />
 
            <br /><br />
            <asp:Button id="Button1"
                Text="Copy Row to Array"
                OnClick="Button_Click"
                runat="server" />
            <br /><br />
            <asp:Label id="Label1"
                runat="server" />
       </p>
 
    </div>
    </form>
</body>
</html>

설명

이 메서드를 사용하여 지정된 인덱스에서 시작하는 지정된 System.Array 에 의 TableCellCollection 내용을 복사합니다.

참고

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

적용 대상

추가 정보