HtmlDocument.GetElementById(String) Yöntem

Tanım

Öğenin HtmlElement özniteliğini arama anahtarı olarak kullanarak tek ID bir öğe alır.

public:
 System::Windows::Forms::HtmlElement ^ GetElementById(System::String ^ id);
public System.Windows.Forms.HtmlElement GetElementById(string id);
member this.GetElementById : string -> System.Windows.Forms.HtmlElement
Public Function GetElementById (id As String) As HtmlElement

Parametreler

id
String

Alınacak öğenin ID özniteliği.

Döndürülenler

Belirtilen değerle aynı ID özniteliğe sahip veya null bulunamazsa id ilk nesneyi döndürür.

Örnekler

Aşağıdaki kod örneği bir belgeden adlandırılmış bir ad TABLE alır, satır sayısını sayar ve sonucu Web sayfasında görüntüler. Kod örneği, projenizde adlı bir WebBrowser denetime sahip olmanız ve özniteliği Table1olan ID bir Web sayfası TABLE yüklemiş olmanız WebBrowser1gerekir.

private Int32 GetTableRowCount(string tableID)
{
    Int32 count = 0;

    if (webBrowser1.Document != null)
    {
        HtmlElement tableElem = webBrowser1.Document.GetElementById(tableID);
        if (tableElem != null)
        {
            foreach (HtmlElement rowElem in tableElem.GetElementsByTagName("TR"))
            {
                count++;
            }
        }
        else
        {
            throw(new ArgumentException("No TABLE with an ID of " + tableID + " exists."));
        }
    }

    return(count);
}
Private Function GetTableRowCount(ByVal TableID As String) As Integer
    Dim Count As Integer = 0

    If (WebBrowser1.Document IsNot Nothing) Then

        Dim TableElem As HtmlElement = WebBrowser1.Document.GetElementById(TableID)
        If (TableElem IsNot Nothing) Then
            For Each RowElem As HtmlElement In TableElem.GetElementsByTagName("TR")
                Count = Count + 1
            Next
        Else
            Throw (New ArgumentException("No TABLE with an ID of " & TableID & " exists."))
        End If
    End If
    GetTableRowCount = Count
End Function

Açıklamalar

Belgede aynı kimlik değerine sahip birden çok öğe varsa, GetElementById bulduğu ilk öğeyi döndürür.

Şunlara uygulanır

Ayrıca bkz.