HtmlTableRowCollection.Count Property
Gets the number of HtmlTableRow objects in the HtmlTableRowCollection.
[Visual Basic] Public Overridable ReadOnly Property Count As Integer Implements _ ICollection.Count [C#] public virtual int Count {get;} [C++] public: __property virtual int get_Count(); [JScript] public function get Count() : int;
Property Value
The number of HtmlTableRow objects in the HtmlTableRowCollection. The default value is 0.
Implements
Remarks
Use the Count property to determine the number of rows contained in the HtmlTableRowCollection. The Count property is commonly used when iterating through the collection to determine the upper bound.
Example
[Visual Basic, C#, JScript] The following example demonstrates how to use the Count property to determine the number of rows in the HtmlTable control. This value is then used as the upper bound of a loop to iterate through the rows of a table.
[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>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="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>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="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>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="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
HtmlTableRowCollection Class | HtmlTableRowCollection Members | System.Web.UI.HtmlControls Namespace | HtmlTableRow | Rows | HtmlTableCell