HtmlTableCellCollection.CopyTo-Methode
Kopiert die Elemente aus der HtmlTableCellCollection-Auflistung in das angegebene System.Array. Dabei wird am angegebenen Index von System.Array begonnen.
Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Public Sub CopyTo ( _
array As Array, _
index As Integer _
)
'Usage
Dim instance As HtmlTableCellCollection
Dim array As Array
Dim index As Integer
instance.CopyTo(array, index)
public void CopyTo (
Array array,
int index
)
public:
virtual void CopyTo (
Array^ array,
int index
) sealed
public final void CopyTo (
Array array,
int index
)
public final function CopyTo (
array : Array,
index : int
)
Parameter
- array
Ein nullbasiertes System.Array, in das die Elemente aus HtmlTableCellCollection kopiert werden.
- index
Der erste Index im angegebenen System.Array, in dem die Elemente abgelegt werden.
Hinweise
Mit dieser Methode können Sie den Inhalt der HtmlTableCellCollection-Auflistung in das angegebene System.Array kopieren. Dabei wird am angegebenen Index des Arrays begonnen.
Hinweis
Der array-Parameter muss ein nullbasiertes System.Array sein.
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie Sie mit der CopyTo-Methode ein Array erstellen, das den gleichen Inhalt wie die HtmlTableCellCollection-Auflistung hat. Anschließend wird das Array durchlaufen, um den Inhalt der HtmlTableCellCollection-Auflistung anzuzeigen.
<%@ Page Language="VB" AutoEventWireup="True" %>
<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>
<head>
<title>HtmlTableCellCollection Example</title>
</head>
<body>
<form runat="server">
<h3>HtmlTableCellCollection Example</h3>
<table id="Table1"
border="1"
bordercolor="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="C#" AutoEventWireup="True" %>
<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>
<head>
<title>HtmlTableCellCollection Example</title>
</head>
<body>
<form runat="server">
<h3>HtmlTableCellCollection Example</h3>
<table id="Table1"
border="1"
bordercolor="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="JScript" AutoEventWireup="True" %>
<script runat="server">
function Button_Click(sender, e : EventArgs)
{
var myCellArray : HtmlTableCell[] = 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.
for (var i : int in myCellArray)
{
Span1.InnerText = Span1.InnerText + " " + myCellArray[i].InnerText;
}
}
</script>
<html>
<head>
<title>HtmlTableCellCollection Example</title>
</head>
<body>
<form runat="server">
<h3>HtmlTableCellCollection Example</h3>
<table id="Table1"
border="1"
bordercolor="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>
Plattformen
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
HtmlTableCellCollection-Klasse
HtmlTableCellCollection-Member
System.Web.UI.HtmlControls-Namespace
System.Array