Note that there are some explanatory texts on larger screens.

plurals
  1. POCast a HtmlGenericControl as a DropDown
    text
    copied!<p>I have quite complicated set of HTML that I want to trawl looking for inputs that match various criteria. I hope to use something along the lines of:</p> <pre><code>private void setup() { masterContainer.InnerHtml = @" &lt;div&gt;crazy &lt;div&gt;unknown &lt;div&gt;html layout &lt;select id='crazySelectIdentifier_id1' runat='server'&gt; &lt;option value='1'&gt;Item1&lt;/option&gt; &lt;option value='2'&gt;Item2&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div&gt; &lt;div&gt; &lt;select id='crazySelectIdentifier_id2' runat='server'&gt; &lt;option value='1'&gt;Item1&lt;/option&gt; &lt;option value='2'&gt;Item2&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt;"; } private void recursiveTrawl(HtmlGenericControl currentOuterControl) { for (int i = 0; i &lt; currentOuterControl.Controls.Count; i++) { HtmlGenericControl currentControl = (HtmlGenericControl) currentOuterControl.Controls[i]; if(currentControl.HasControls()) { recursiveTrawl(currentControl); } else { String[] controlArr = currentControl.ID.ToString().Split('_'); String currentId = controlArr[1]; if (currentId.Equals("somethingspecific")) { //THE PROBLEM IS HERE DropDownList dropdown = (DropDownList)currentControl; </code></pre> <p>However, I get the error- Cannot convert type 'System.Web.UI.HtmlControls.HtmlGenericControl' to 'System.Web.UI.WebControls.DropDownList'</p> <p>I've tried using HtmlSelect as well with a similiar error. I just need to know how I can get access to the selected values in the drop down lists I'm interested in.</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload