简体   繁体   中英

C# web browser fill com box on selected change

i have got 3 html drop down list the second drop down get its values on first changed and the third gets its value on second changed how can i pass the values to combox using webbrower control and handle the same thing on combox1 value or index changed the second combox2 set new values and so on the third i had trial this is the html code and my trial ? thanks for all .

------DropDown1-------

------DropDown2-------

------DropDown3-------

        <select name="DDL1" onchange="javascript:setTimeout('__doPostBack(\'DDL1\',\'\')', 0)" id="DDL1">
            <option selected="selected" value="0">select from list </option>
            <option value="1">v1 </option>
            <option value="2">v2</option>
            <option value="4">v3</option>
            <option value="5">v4/option>
            <option value="6">v5<option>

        </select>
 <select name="DDL2" onchange="javascript:setTimeout('__doPostBack(\'DDL1\',\'\')', 0)" id="DDL2">
    <option selected="selected" value="0">select from list2 </option>

</select>
<select name="DDL3" onchange="javascript:setTimeout('__doPostBack(\'DDL3\',\'\')', 0)" id="DDL1">
    <option selected="selected" value="0">select from list3 </option>
</select>

foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("select"))
                {
                    if (el.Id == "DDL1")
                    {
                        foreach (HtmlElement comboItem in el.Children)
                        {
                            comboBox1.Items.Add(comboItem.InnerText);
                            if (comboItem.InnerText == "select from list")
                            {
                                comboBox1.SelectedItem = comboItem.InnerText;
                            }

                        }
                    }
                }

Use this;

HtmlDocument doc = this.webBrowser1.Document;
doc.GetElementById("myId").SetAttribute("Value", "someValue");

I got the code from This Post , I hope that helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM