HtmlTableRow Control
Creates a server-side control that maps to the <tr> HTML element and allows you to create and manipulate a row in a table.
<tr id="programmaticID"
align="tablecontentalignment"
bgcolor="tablebgcolor"
bordercolor="bordercolor"
height="tableheight"
cells="collectionoftablecells"
valign="verticalalignmentofrowcontent" >
<td>cellcontent</td>
<td>cellcontent</td>
<td>cellcontent</td>
</tr>
Remarks
Use the HtmlTableRow class to program against the <tr> HTML element. A <tr> element represents a row in the table.
The HtmlTableRow class allows you to control the appearance of each individual row in the table. You can control the background color, border color, and height of the row by setting the BgColor, BorderColor, and Height properties, respectively.
The horizontal and vertical alignment of the contents of the cells in the row are controlled by setting the Align and VAlign properties, respectively.
Each row in the table contains a Cells collection, which contains an HtmlTableCell for each cell in the row.
Example
The following example demonstrates how use an HtmlTableCell to modify the contents of a cell in the HtmlTable control.
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
Sub Button_Click(sender As Object, e As EventArgs)
Dim i As Integer
Dim j As Integer
' Iterate through the rows of the table.
For i=0 To Table1.Rows.Count - 1
' Iterate through the cells of a row.
For j=0 To Table1.Rows(i).Cells.Count - 1
' Change the inner HTML of the cell.
Table1.Rows(i).Cells(j).InnerHtml = "Row " & i.ToString() _
& ", Column " & _
j.ToString()
Next j
Next i
End Sub
</script>
</head>
<body>
<form runat="server">
<h3>HtmlTableCell 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="Change Table Contents"
OnServerClick = "Button_Click"
runat="server"/>
</form>
</body>
</html>
[C#]
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
void Button_Click(Object sender, EventArgs e)
{
// Iterate through the rows of the table.
for (int i=0; i<=Table1.Rows.Count - 1; i++)
{
// Iterate through the cells of a row.
for (int j=0; j<=Table1.Rows[i].Cells.Count - 1; j++)
{
// Change the inner HTML of the cell.
Table1.Rows[i].Cells[j].InnerHtml = "Row " + i.ToString() +
", Column " +
j.ToString();
}
}
}
</script>
</head>
<body>
<form runat="server">
<h3>HtmlTableCell 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="Change Table Contents"
OnServerClick = "Button_Click"
runat="server"/>
</form>
</body>
</html>
See Also
ASP.NET Syntax for HTML Controls | HtmlTableRow Class | HtmlTableCell Control | HtmlTable Control | System.Web.UI.HtmlControls Namespace | System.Web.UI.HtmlControls Namespace