HtmlTableCellCollection.Count 속성

정의

HtmlTableCellCollection 컬렉션의 HtmlTableCell 개체 수를 가져옵니다.

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

속성 값

Int32

HtmlTableCellHtmlTableCellCollection 개체 수입니다. 기본값은 0입니다.

구현

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 Count 행의 셀 수를 확인 하는 속성은 HtmlTable 컨트롤입니다. 이 값 다음 테이블에서 행의 셀을 반복 하는 루프의 상한으로 사용 됩니다.

<%@ 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 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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableCellCollection Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTableCellCollection Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color: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="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 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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableCellCollection Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTableCellCollection Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color: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>

설명

사용 합니다 Count 속성에 포함 된 셀의 수를 확인 하는 HtmlTableCellCollection 컬렉션입니다. Count 속성은 위를 결정 하기 위해 컬렉션을 반복할 때 일반적으로 사용 됩니다.

적용 대상

추가 정보