HtmlTableRow.Cells Property
Gets a collection of HtmlTableCell objects that represent the cells contained in a row of the HtmlTable control.
[Visual Basic] Public Overridable ReadOnly Property Cells As _ HtmlTableCellCollection [C#] public virtual HtmlTableCellCollection Cells {get;} [C++] public: __property virtual HtmlTableCellCollection* get_Cells(); [JScript] public function get Cells() : HtmlTableCellCollection;
Property Value
An HtmlTableCellCollection that contains the cells of a row in an HtmlTable control.
Remarks
Use the Cells collection to programmatically access the cells of a row in an HtmlTable control. You can programmatically add, remove, and insert cells into the collection.
Note If there are no cells defined in a row, an empty HtmlTableCellCollection is returned.
Example
[Visual Basic, C#, JScript] The following example demonstrates how to use the Cells collection to iterate through the cells of a row, represented by an HtmlTableRow. The contents of the cells are then updated with new content.
[Visual Basic] <%@ 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>HtmlTableRow 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>HtmlTableRow 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> [JScript] <%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> <script runat="server"> function Button_Click(sender, e : EventArgs) { // Iterate through the rows of the table. for (var i : int=0; i<=Table1.Rows.Count - 1; i++) { // Iterate through the cells of a row. for (var j : int =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>HtmlTableRow 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++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
HtmlTableRow Class | HtmlTableRow Members | System.Web.UI.HtmlControls Namespace | HtmlTableCellCollection