html get elements dropdownlist vbnet

时间:2015-08-02 18:16:10

标签: asp.net vb.net

我正在尝试收集html下拉列表中的所有项目,并将它们放在vbet中的我的combobx中,但是我收到的错误是索引超出范围。我检查了下拉列表的ID,但它是正确的。< / p>

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim I As Integer = 0
    Dim NAME As String


    NAME = WebBrowser1.document.GetElementById("ID").GetAttribute("pt1:r1:0:soc2::content").GetAttribute("value").ElementAt(I)
    ComboBox1.Items.Add(NAME)
    MessageBox.Show(NAME)



End Sub

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我现在编写了这段代码,一切都很完美。

希望它有所帮助:

For Each elem In WebBrowser1.Document.GetElementById("pt1:r1:0:soc2::content").Children
     ComboBox1.Items.Add(WebBrowser1.Document.Body.AppendChild(elem).InnerText)
     MessageBox.Show(WebBrowser1.Document.Body.AppendChild(elem).InnerText)
Next

乔纳森