HtmlTableRowCollection Class
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.
A collection of HtmlTableRow objects that represent the rows of an HtmlTable control. This class cannot be inherited.
public ref class HtmlTableRowCollection sealed : System::Collections::ICollection
public sealed class HtmlTableRowCollection : System.Collections.ICollection
type HtmlTableRowCollection = class
interface ICollection
interface IEnumerable
Public NotInheritable Class HtmlTableRowCollection
Implements ICollection
- Inheritance
-
HtmlTableRowCollection
- Implements
The following code example demonstrates how to dynamically generate the contents of an HtmlTable control by adding rows to an HtmlTableRowCollection collection. Notice that the Rows property of a table is the HtmlTableRowCollection object.
<%@ 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 Page_Load(Object sender, EventArgs e)
{
// Get the number of rows and columns selected by the user.
int numrows = Convert.ToInt32(Select1.Value);
int numcells = Convert.ToInt32(Select2.Value);
// Iterate through the rows.
for (int j = 0; j < numrows; 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 < numcells; 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 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"
style="border-width:1; border-color:Black; padding:5"
cellspacing="0"
runat="server" />
<hr />
Select the number of rows and columns to create: <br /><br />
Table rows:
<select id="Select1"
runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
Table cells:
<select id="Select2"
runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<br /><br />
<input type="submit"
value="Generate Table"
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 Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim i As Integer
Dim j As Integer
Dim row As HtmlTableRow
Dim cell As HtmlTableCell
' Get the number of rows and columns selected by the user.
Dim numrows As Integer = CInt(Select1.Value)
Dim numcells As Integer = CInt(Select2.Value)
' Iterate through the rows.
For j = 0 To numrows - 1
' 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 numcells - 1
' 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 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"
style="border-width:1; border-color:Black; padding:5"
cellspacing="0"
runat="server" />
<hr />
Select the number of rows and columns to create: <br /><br />
Table rows:
<select id="Select1"
runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
Table cells:
<select id="Select2"
runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<br /><br />
<input type="submit"
value="Generate Table"
runat="server"/>
</form>
</body>
</html>
Use the HtmlTableRowCollection class to programmatically manage a collection of HtmlTableRow objects that represent the rows in an HtmlTable control. This class is commonly used to add, remove, or modify the contents of a row in an HtmlTable control.
Nota
An HtmlTable control contains a Rows property that represents a collection of HtmlTableRow objects. Each HtmlTableRow represents an individual row in the table. An HtmlTableRow contains a Cells property that represents a collection of HtmlTableCell objects. These objects, in turn, represent the individual cells of the table. To retrieve an individual cell, first get the HtmlTableRow object, representing the row containing the cell, from the Rows collection of the HtmlTable control. You can then get the HtmlTableCell object, representing the cell in the row, from the Cells collection of the HtmlTableRow.
Count |
Gets the number of HtmlTableRow objects in the HtmlTableRowCollection collection. |
Is |
Gets a value indicating whether the HtmlTableRowCollection collection is read-only. |
Is |
Gets a value indicating whether access to the HtmlTableRowCollection collection is synchronized (thread safe). |
Item[Int32] |
Gets the HtmlTableRow object at the specified index from the HtmlTableRowCollection collection. |
Sync |
Gets the object that can be used to synchronize access to the HtmlTableRowCollection collection. |
Add(Html |
Appends the specified HtmlTableRow object to the end of the HtmlTableRowCollection collection. |
Clear() |
Removes all HtmlTableRow objects from the HtmlTableRowCollection collection. |
Copy |
Copies the items from the HtmlTableRowCollection collection to the specified Array object, starting at the specified index in the array. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Returns an IEnumerator-implemented object that contains all HtmlTableRow objects in the HtmlTableRowCollection collection. |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Insert(Int32, Html |
Adds an HtmlTableRow object to the specified location in the collection. |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
Remove(Html |
Removes the specified HtmlTableRow object from the HtmlTableRowCollection collection. |
Remove |
Removes the HtmlTableRow object at the specified index from the HtmlTableRowCollection collection. |
To |
Returns a string that represents the current object. (Inherited from Object) |
Cast<TResult>(IEnumerable) |
Casts the elements of an IEnumerable to the specified type. |
Of |
Filters the elements of an IEnumerable based on a specified type. |
As |
Enables parallelization of a query. |
As |
Converts an IEnumerable to an IQueryable. |
Produto | Versões |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Comentários do .NET
O .NET é um projeto código aberto. Selecione um link para fornecer comentários: