HtmlTableCellCollection.CopyTo(Array, Int32) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Copies the items from the HtmlTableCellCollection collection to the specified Array, beginning with the specified index in the 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)
Parameters
- array
- Array
A zero-based Array that receives the copied items from the HtmlTableCellCollection.
Implements
Examples
The following code example demonstrates how to use the CopyTo method to create an array that contains the same contents as the HtmlTableCellCollection collection. The array is then iterated through to display the contents of the HtmlTableCellCollection collection.
<%@ 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)
{
HtmlTableCell[] myCellArray = new HtmlTableCell[2];
// Copy the collection to an array.
Table1.Rows[0].Cells.CopyTo(myCellArray, 0);
Span1.InnerText = "The copied items from the selected row are: ";
// Iterate through the array and display its contents.
foreach (HtmlTableCell cell in myCellArray)
{
Span1.InnerText = Span1.InnerText + " " + cell.InnerText;
}
}
</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"
runat="server">
<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 the contents of the first row"
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 myCellArray(1) As HtmlTableCell
Dim cell As HtmlTableCell
' Copy the collection to an array.
Table1.Rows(0).Cells.CopyTo(myCellArray, 0)
Span1.InnerText = "The copied items from the selected row are: "
' Iterate through the array and display its contents.
For Each cell In myCellArray
Span1.InnerText = Span1.InnerText & " " & cell.InnerText
Next cell
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"
runat="server">
<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 the contents of the first row"
onserverclick="Button_Click"
runat="server"/>
<br /><br />
<span id="Span1"
runat="server"/>
</form>
</body>
</html>
Remarks
Use this method to copy the contents of the HtmlTableCellCollection collection into the specified System.Array, starting at the specified index of the array.
Note
The array
parameter must be a zero-based System.Array.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기