Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Entfernt sämtliche HtmlTableRow-Objekte aus der HtmlTableRowCollection-Auflistung.
Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Public Sub Clear
'Usage
Dim instance As HtmlTableRowCollection
instance.Clear
public void Clear ()
public:
void Clear ()
public void Clear ()
public function Clear ()
Hinweise
Mit dieser Methode können Sie alle HtmlTableRow-Objekte aus der HtmlTableRowCollection-Auflistung entfernen und die Count-Eigenschaft auf 0 zurücksetzen.
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie mit der Clear-Methode alle Elemente aus der HtmlTableRowCollection-Auflistung entfernt werden. Anschließend werden der Auflistung neue Einträge hinzugefügt und diese im HtmlTable-Steuerelement angezeigt.
<%@ Page Language="VB" AutoEventWireup="True" %>
<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>
<head>
<title>HtmlTableRowCollection Example</title>
</head>
<body>
<form runat="server">
<h3>HtmlTableRowCollection 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="Create New Table"
onserverclick="Button_Click"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<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>
<head>
<title>HtmlTableRowCollection Example</title>
</head>
<body>
<form runat="server">
<h3>HtmlTableRowCollection 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="Create New Table"
onserverclick="Button_Click"
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
HtmlTableRowCollection-Klasse
HtmlTableRowCollection-Member
System.Web.UI.HtmlControls-Namespace
HtmlTableCell-Klasse
HtmlTableRow-Klasse
HtmlTableRow.Cells-Eigenschaft
Count