Aracılığıyla paylaş


TableRowCollection.GetRowIndex(TableRow) Yöntem

Tanım

içinden TableRowCollectionbelirtilen TableRow dizinini temsil eden bir değer döndürür.

public:
 int GetRowIndex(System::Web::UI::WebControls::TableRow ^ row);
public int GetRowIndex (System.Web.UI.WebControls.TableRow row);
member this.GetRowIndex : System.Web.UI.WebControls.TableRow -> int
Public Function GetRowIndex (row As TableRow) As Integer

Parametreler

row
TableRow

TableRow içinde TableRowCollectionaranacak nesne.

Döndürülenler

Koleksiyon içinde belirtilen TableRow sıralı dizin konumu. Varsayılan değer -1'dir ve bu da belirtilenin TableRow bulunamadığını gösterir.

Örnekler

Aşağıdaki örnekte, seçili hücrenin satır dizinini GetRowIndex görüntülemek için özelliğinin nasıl kullanılacağı gösterilmektedir.

<%@ 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;

        // 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();
                if (cellNum == List2.SelectedIndex)
                    cel.BackColor = System.Drawing.Color.Chartreuse;
                else if (rowNum == List1.SelectedIndex)
                    cel.BackColor = System.Drawing.Color.CadetBlue;
                else
                    cel.BackColor = System.Drawing.Color.White;
                rw.Cells.Add(cel);
                counter++;
            }
            Table1.Rows.Add(rw);
        }

        if (!IsPostBack)
        {
            // Fill a DropDownList with row numbers
            for (int rowNum = 0; rowNum < numRows; rowNum++)
            {
                List1.Items.Add(rowNum.ToString());
            }

            // Fill a DropDownList with column numbers
            for (int cellNum = 0; cellNum < numCells; cellNum++)
            {
                List2.Items.Add(cellNum.ToString());
            }
        }
    }

    void Button_Click(object sender, EventArgs e)
    {
        int rowNum = List1.SelectedIndex;
        TableRow rw = Table1.Rows[rowNum];

        Label1.Text = "The row index of the selected cell is " +
            Table1.Rows.GetRowIndex(rw).ToString();
    }
</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 /> <br />
        Select a cell:
        <br /> <br />
        Row: <asp:DropDownList id="List1" runat="server" />
        Column: <asp:DropDownList id="List2" runat="server" />
        <br /> <br />
        <asp:Button id="Button1"
           Text="Get Index"
           OnClick="Button_Click"
           runat="server" />
        <br /> <br />
        <asp:Label id="Label1" runat="server" />
    </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 cellNum As Integer
        Dim counter As Integer = 1

        ' Create a table.
        Dim rowNum As Integer
        For rowNum = 0 To numRows - 1
            Dim rw As New TableRow()
            For cellNum = 0 To numCells - 1
                Dim cel As New TableCell()
                cel.Text = counter.ToString()
                If cellNum = List2.SelectedIndex Then
                    cel.BackColor = System.Drawing.Color.Chartreuse
                ElseIf rowNum = List1.SelectedIndex Then
                    cel.BackColor = System.Drawing.Color.CadetBlue
                Else
                    cel.BackColor = System.Drawing.Color.White
                End If
                rw.Cells.Add(cel)
                counter += 1
            Next cellNum
            Table1.Rows.Add(rw)
        Next rowNum
            
        If Not IsPostBack Then
            ' Fill a DropDownList with row numbers
            For rowNum = 0 To numRows - 1
                List1.Items.Add(rowNum.ToString())
            Next rowNum
                
            ' Fill a DropDownList with column numbers
            For cellNum = 0 To numCells - 1
                List2.Items.Add(cellNum.ToString())
            Next cellNum
        End If
    End Sub

    Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim rowNum As Integer = List1.SelectedIndex
        Dim rw As TableRow = Table1.Rows(rowNum)
            
        Label1.Text = "The row index of the selected cell is " & _
            Table1.Rows.GetRowIndex(rw).ToString()
    End Sub
</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 /> <br />
        Select a cell:
        <br /> <br />
        Row: <asp:DropDownList id="List1" runat="server" />
        Column: <asp:DropDownList id="List2" runat="server" />
        <br /> <br />
        <asp:Button id="Button1"
           Text="Get Index"
           OnClick="Button_Click"
           runat="server" />
        <br /> <br />
        <asp:Label id="Label1" runat="server" />
    </div>
    </form>
</body>
</html>

Açıklamalar

içinde TableRowCollectionbelirtilen TableRow dizinini belirlemek için bu yöntemi kullanın. Belirtilen TableRow bulunamazsa, -1 dizini döndürülür.

Şunlara uygulanır

Ayrıca bkz.