Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi every body 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 the problem is that when i select any value for the first time it fill the com boxes as if it s the first time repeat the default one then when i select another value of drop down list it gets data correctly for the item which selected before not the current selected item and so on its also add the data on the previous selected item suppose it clears and fill with the new one this is the code .

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

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

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

i have tried the code from previous post

C# web browser select list item click[^]

What I have tried:

C#
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
       {
           if (isUIClick1)
               SetComboItem("DD1", comboBox1.Text);
           isUIClick1 = false;
       }

     public void SetComboItem(string id, string value)
       {

           HtmlElement ddl = webBrowser1.Document.GetElementById(id);
           foreach (HtmlElement item in ddl.Children)
           {

               if (item.InnerText == value)
               {
                   value = item.GetAttribute("Value");
                   break;
               }
           }



           foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("select"))
           {
               if (el.Id == "DDl2")
                   FillComboBox(el, comboBox2);
               else if (el.Id == "DD3")
                   FillComboBox(el, comboBox3);


           }


private void FillComboBox(HtmlElement el, System.Windows.Forms.ComboBox cbx)
       {
           bool selected = false;
           string selectedText = "";

               foreach (HtmlElement comboItem in el.Children)

               cbx.Items.Add(comboItem.InnerText);


           foreach (HtmlElement comboItem in el.Children)
           {
               selected = Convert.ToBoolean(comboItem.GetAttribute("Selected"));
               if (selected)
               {
                   selectedText = comboItem.InnerText;
                   break;
               }
           }
           cbx.Text = selectedText;
       }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900