下面是下拉列表的的HTML代码,现在默认的选择是“苹果”,要用webBrowse模拟选择“橘子”(即更改原来默认的选择)代码该如何写?请指教,先谢谢了。<TR>
                <TD class=colorred align=right>水果</TD>
                <TD align=left colSpan=3><SELECT id=fruit 
                  <OPTION value=8 selected>苹果</OPTION> <OPTION 
                    value=7>橘子</OPTION> <OPTION value=4>香蕉</OPTION></SELECT> 
                  </SELECT></TD></TR>
              <TR>

解决方案 »

  1.   

    翻了下MSDN ,你看下这段代码:private void ShiftRows(String tableName)
            {
                if (webBrowser1.Document != null)
                {
                    HtmlDocument doc = webBrowser1.Document;
                    HtmlElementCollection elems = doc.All.GetElementsByName(tableName);
                    if (elems != null && elems.Count > 0)
                    {
                        HtmlElement elem = elems[0];                    // Prepare the arguments.
                        Object[] args = new Object[2];
                        args[0] = (Object)"-1";
                        args[1] = (Object)"0";                    elem.InvokeMember("moveRow", args);
                    }
                }
            }
      

  2.   

    HtmlElement s= null;
    if (webBrowser1.Document.All[i].GetAttribute("value") == "")
    {
      s= webBrowser1.Document.All[i];
      s.SetAttribute("checked", "checked");
    }mshtml.dll   
    using mshtml
    mshtml.IHTMLSelectElement select =(mshtml.IHTMLSelectElement)  
    webBrowser1.Document.GetElementById("").DomElement;  
    select.selectedIndex =3;  
      

  3.   

    jx0797,谢谢,还是不太明白。在W3School上看了看select的相关资料:《selected 属性可设置或返回选项的 selected 属性的值。
    该属性设置选项的当前状态,如果为 true,则该选项被选中。该属性的初始值来自 <option> 的 selected 属性。》应该是改变option的selected属性,谁知道怎么改啊?
      

  4.   

    你看下wuyq11   mshtml.dll这段 ,这个要添加mshtml.dll引用
      

  5.   

    wuyq11,下面的代码是做何用的啊?
    HtmlElement s= null;
    if (webBrowser1.Document.All[i].GetAttribute("value") == "")
    {
      s= webBrowser1.Document.All[i];
      s.SetAttribute("checked", "checked");
    }
      

  6.   

     HtmlDocument doc = tempBrowser.Document;   
    IHTMLSelectElement select = (IHTMLSelectElement)doc.GetElementById("fruit").DomElement;
                        select.selectedIndex = 1;
    我是这样写的,但总是报错,说是“未将对象引用设置到对象的实例”,这是什么原因造成的啊
      

  7.   

    终于明白了这段代码的意思:wuyq11其实是告诉了我两种解决方法,这种比较简单,就是搜索到select中的“fruit”然后对fruit的“selectedIndex"进行赋值即可。谢谢!