다음을 통해 공유


TableCellCollection.Item[Int32] 속성

정의

지정된 인덱스에 있는 TableCell으로부터 TableCellCollection를 가져옵니다.

public:
 property System::Web::UI::WebControls::TableCell ^ default[int] { System::Web::UI::WebControls::TableCell ^ get(int index); };
public System.Web.UI.WebControls.TableCell this[int index] { get; }
member this.Item(int) : System.Web.UI.WebControls.TableCell
Default Public ReadOnly Property Item(index As Integer) As TableCell

매개 변수

index
Int32

반환할 TableCell를 지정하는 서수 인덱스 값입니다.

속성 값

TableCell의 요소를 나타내는 TableCellCollection입니다.

예제

다음 예에서는 인덱서 를 사용하여 에서 을 TableCell 가져오는 방법을 보여 줍니다 TableCellCollection. 예제에서 의 CellsTableRow 속성은 클래스의 TableCellCollection 인스턴스입니다.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    void Page_Load(Object sender, EventArgs e)
    {
        int numRows = 5;
        int numcells = 6;
        int counter = 1;
        ArrayList a_row = new ArrayList();
        ArrayList a_column = new ArrayList();

        // Create a table.
        for (int rowNum = 0; rowNum < numRows; rowNum++)
        {
            TableRow rw = new TableRow();
            for (int cellNum = 0; cellNum < numcells; cellNum++)
            {
                TableCell cel = new TableCell();
                cel.Text = counter.ToString();
                rw.Cells.Add(cel);
                counter++;
            }
            Table1.Rows.Add(rw);
        }

        if (!IsPostBack)
        {
            // Create a DropDownList for the number of columns.
            for (int cellNum = 0; cellNum < numcells; cellNum++)
            {
                a_column.Add(cellNum.ToString());
            }

            // Create a DropDownList for the number of rows.
            for (int rowNum = 0; rowNum < numRows; rowNum++)
            {
                a_row.Add(rowNum.ToString());
            }

            List1.DataSource = a_column;
            List2.DataSource = a_row;
            List1.DataBind();
            List2.DataBind();
        }
    }

    void Button_Click(object sender, EventArgs e)
    {
        int column = List1.SelectedIndex;
        int row = List2.SelectedIndex;

        string spec = "The cell ({0}, {1}) contains the value {2}.";
        Label1.Text = String.Format(spec, column,
            row, Table1.Rows[row].Cells[column].Text);
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>TableCellCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <h3>TableCellCollection Example</h3>
    <asp:Table id="Table1" 
        runat="server"/>
    <br />&nbsp;<br />
    <p>Select a column and row:<br />
        Column: <asp:DropDownList id="List1" 
            runat="server"/>
        Row: <asp:DropDownList id="List2"
            runat="server"/>
        <br />&nbsp;<br />
        <asp:Button id="Button1"
            Text="Display Cell Value"
            OnClick="Button_Click"
            runat="server"/>
        <br />&nbsp;<br />
        <asp:Label id="Label1"
            runat="server"/>
    </p>

    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim numRows As Integer = 5
        Dim numCells As Integer = 6
        Dim counter As Integer = 1
        Dim a_row As New ArrayList()
        Dim a_column As New ArrayList()

        ' Create a table.
        Dim rowNum As Integer
        For rowNum = 0 To numRows - 1
            Dim rw As New TableRow()
            Dim cellNum As Integer
            For cellNum = 0 To numCells - 1
                Dim cel As New TableCell()
                cel.Text = counter.ToString()
                rw.Cells.Add(cel)
                counter += 1
            Next
            Table1.Rows.Add(rw)
        Next

        If Not IsPostBack Then
            ' Create a DropDownList for the number of columns.
            Dim cellNum As Integer
            For cellNum = 0 To numCells - 1
                a_column.Add(cellNum.ToString())
            Next

            ' Create a DropDownList for the number of rows.
            For rowNum = 0 To numRows - 1
                a_row.Add(rowNum.ToString())
            Next

            List1.DataSource = a_column
            List2.DataSource = a_row
            List1.DataBind()
            List2.DataBind()
        End If
    End Sub

    Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim column As Integer = List1.SelectedIndex
        Dim row As Integer = List2.SelectedIndex
        
        Dim spec As String
        spec = "The cell ({0}, {1}) contains the value {2}."
        Label1.Text = String.Format(spec, column, _
            row, Table1.Rows(row).Cells(column).Text)
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <h3>TableCellCollection Example</h3>
    <asp:Table id="Table1" 
        runat="server"/>
    <br />&nbsp;<br />
    <p>Select a column and row:<br />
        Column: <asp:DropDownList id="List1" 
            runat="server"/>
        Row: <asp:DropDownList id="List2"
            runat="server"/>
        <br />&nbsp;<br />
        <asp:Button id="Button1"
            Text="Display Cell Value"
            OnClick="Button_Click"
            runat="server"/>
        <br />&nbsp;<br />
        <asp:Label id="Label1"
            runat="server"/>
    </p>

    </div>
    </form>
</body>
</html>

설명

이 인덱서는 간단한 배열 표기법을 사용하여 지정된 인덱스에서 의 개인 TableCellTableCellCollection 을 가져옵니다.

적용 대상

추가 정보