Click here to Skip to main content
15,900,378 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 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

HTML
        </td>
        <td align="right" style="height: 33px" colspan="2">
            <select name="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>
        </td>

<td align="right" style="height: 33px" colspan="2">
    <select name="DDL2" >
        <option selected="selected" value="0">select from list2 </option>

    </select>
</td>

<td align="right" style="height: 33px" colspan="2">
    <select name="DDL3" >
        <option selected="selected" value="0">select from list3 </option>


    </select>
</td>


What I have tried:

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;
}

}
}
}
Posted
Updated 27-May-16 7:43am
Comments
Karthik_Mahalingam 27-May-16 5:57am    
does DDL2 and DDL3 has all the values ?
MR.alaa 27-May-16 6:06am    
no it depends on selected value from DD1 on select item it populate dd2 and so on
Karthik_Mahalingam 27-May-16 10:02am    
Always use  Reply  button, to post Comments/query to the user, else the User wont get notified.
Karthik_Mahalingam 27-May-16 10:04am    
so, on selection of the 3rd drop down only we can load all the combo box?
does post back happens on the drop down selection ?
if not the it is not possible to achieve unless there is a button or some ctrl to invoke this action.
MR.alaa 27-May-16 12:55pm    
thankx for advice on selection of the 1s down only we can load all the combox and they change their values if 1st change
there is postback in each dropdownlist
<select name="DDL1" >

1 solution

try this

C#
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
      {
          comboBox1.Items.Clear();
          comboBox2.Items.Clear();
          comboBox3.Items.Clear();

          foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("select"))
          {

              if (el.Id == "DDL1")
                  FillComboBox(el, comboBox1);
              else if (el.Id == "DDL2")
                  FillComboBox(el, comboBox2);
              else if (el.Id == "DDL3")
                  FillComboBox(el, comboBox3);

          }
      }

      private void FillComboBox(HtmlElement el, 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;
      }
 
Share this answer
 
Comments
MR.alaa 27-May-16 13:53pm    
thanks for the code but on selectchanged of combox 1st webcontol doent fire how fill the 2nd combox should we use
webBrowser1.Document.InvokeScript("__doPostBack")
or
el.RaiseEvent("onChange");
Karthik_Mahalingam 27-May-16 13:55pm    
you mean reverse code ?
Karthik_Mahalingam 27-May-16 14:10pm    
add this code..
Create selectedindexevent for the 3 comboboxes


private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SetComboItem("DDL1", comboBox1.Text);
}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
SetComboItem("DDL2", comboBox2.Text);
}

private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
SetComboItem("DDL3", comboBox3.Text);
}

public void SetComboItem(string id, string value)
{
HtmlElement ee = this.webBrowser1.Document.GetElementById(id);
foreach (HtmlElement item in ee.Children)
{
if (item.InnerText.ToLower().IndexOf(value.ToLower()) >= 0)
{
item.SetAttribute("selected", "selected");
item.InvokeMember("onChange");
}
else
{
item.SetAttribute("selected", "");
}
}


}

Play around with these codes, you will get the solution.
Gonna sleep now, getting late. catch you later .. Good luck :)
MR.alaa 27-May-16 14:22pm    
nothing happened its only reload without get any data suppose make even handler for webbrower control to refresh the page to get new data ?? on selected changedindex
MR.alaa 27-May-16 14:28pm    
many thanks for if i reach Solution i will tell you happy dreams

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



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