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:
private void setup()
{
masterContainer.InnerHtml = @"
<div>crazy
<div>unknown
<div>html layout
<select id='crazySelectIdentifier_id1' runat='server'>
<option value='1'>Item1</option>
<option value='2'>Item2</option>
</select>
</div>
</div>
</div>
<div>
<div>
<select id='crazySelectIdentifier_id2' runat='server'>
<option value='1'>Item1</option>
<option value='2'>Item2</option>
</select>
</div>
</div>
<div>
</div>";
}
private void recursiveTrawl(HtmlGenericControl currentOuterControl)
{
for (int i = 0; i < 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;
However, I get the error- Cannot convert type 'System.Web.UI.HtmlControls.HtmlGenericControl' to 'System.Web.UI.WebControls.DropDownList'
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.
Thanks in advance.