网页代码是这样的     <select name="DdlTypeId" id="DdlTypeId">
<option value="1">便携式心电</option>
<option value="2">无线血压</option>
<option value="3">无线血氧</option>
<option selected="selected" value="4">无线脂肪</option>
</select>
      
  请问如何获取到选中的值? 就是有“selected”的“无线脂肪”;

解决方案 »

  1.   

    遍历,看attribute中有selected属性,为selected的就是了。
      

  2.   

    HtmlElement s= null;
    if (webBrowser1.Document.All[i].GetAttribute("value") == "")
    {
      s= webBrowser1.Document.All[i];
      s.SetAttribute("checked", "checked");
    }
      

  3.   

     我是这样取的  
    if (sender is WebBrowser)
                    {
                       WebBrowser webbr =  (WebBrowser)sender;
                       HtmlElementCollection btn_Label = webbr.Document.GetElementsByTagName("span");                   if (webbr.Name.EndsWith("Equipment"))
                       {
                           HtmlElementCollection inputSqltem = webbr.Document.GetElementsByTagName("select");
                           foreach (HtmlElement eltems in inputSqltem)
                           {
                               if (eltems.GetAttribute("ID").ToString().Equals("DdlTypeId"))
                               {
                                   temss = eltems.GetAttribute("selected").ToString();
                                   break;
                               }
                           }
                       }      但是获取的temss老是空的。没有值啊。是不是写的不对?
      

  4.   

    int selectedIndex=Convert.ToInt32(heSelct.GetAttribute("selectedIndex"));
    heSelct.GetElementsByTagName("option")[selectedIndex].OuterText;