HtmlTableRowCollection.Count プロパティ
アセンブリ: System.Web (system.web.dll 内)

HtmlTableRowCollection 内の HtmlTableRow オブジェクトの数。既定値は 0 です。

Count プロパティを使用して、HtmlTableRowCollection コレクションに格納されている行数を確認します。通常、Count プロパティは、コレクションを反復処理して上限を確認する場合に使用されます。

Count プロパティを使用して、HtmlTable コントロール内の行数を確認する方法を次のコード例に示します。この値は、この後でテーブルの行に対して行う反復処理ループの上限値として使用します。
<%@ 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 ' 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> <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="Change Table Contents" onserverclick="Button_Click" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <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> <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="Change Table Contents" onserverclick="Button_Click" runat="server"/> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <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> <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="Change Table Contents" onserverclick="Button_Click" runat="server"/> </form> </body> </html>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- HtmlTableRowCollection.Count プロパティのページへのリンク