How can I add an unknownn number of dropdownlists programatically to a page and retrieve the selected values with c# on submit
<p>I'm trying to do this and it is a bit confusing for me.</p>

<p>Basically the scenario is like this, I'm getting an XML from a 3rd party application with available dates for booking, for each day there are types of rooms the person can choose, single, double, etc. </p>

<p>Each hostel will return me an unknown number of room types. But dont get too confused with this. </p>

<p>The thing is simple I just need to add an unknown number of dropdownlists (or HTML Select) with the numbers of persons to book for. Now because I don't know how many of those dropdowns I will have I need to add them programatically inside a "for int i=0; i

<p>How can I add an unknownn number of dropdownlists programatically to a page and retrieve the selected values with c# on submit?</p>

<p>The last column on the screenshot</p>

<p><a href="http://i.stack.imgur.com/37chw.png" rel="nofollow">http://i.stack.imgur.com/37chw.png</a></p>

<p><strong>Update:</strong></p>

<p>I'm creating the code from the xml results as a string that will print as html code:</p>

<pre><code> XmlDocument xmlDoc2 = new XmlDocument();
    xmlDoc.LoadXml(getPrices());
    XmlNodeList prices = xmlDoc.GetElementsByTagName("RoomType");

    string[] bookingDates = new string[Convert.ToInt32(Request.QueryString["nights"])];
    string[] bookingDays = new string[Convert.ToInt32(Request.QueryString["nights"])];
    bookingDates[0] = Request.QueryString["date"].ToString();

    string[] dateArray = Request.QueryString["date"].ToString().Split('-');
    DateTime initialDate = new DateTime(Convert.ToInt32(dateArray[0]), Convert.ToInt32(dateArray[1]), Convert.ToInt32(dateArray[2]));
    bookingDays[0] = initialDate.DayOfWeek.ToString();
    for (int z = 1; z &lt; bookingDates.Length; z++)
    {
        DateTime nextDay = initialDate.AddDays(z);
        string month = nextDay.Month.ToString();
        string day = nextDay.Day.ToString();
        if (day.Length == 1)
        {
            day = "0" + day;
        }
        if (month.Length == 1)
        {
            month = "0" + month;
        }
        bookingDates[z] = nextDay.Year + "-" + month + "-" + day;
        bookingDays[z] = nextDay.DayOfWeek.ToString();
    }
    string pricesHeader = "&lt;table width='100%'&gt;";
    pricesHeader += "&lt;tr&gt;&lt;td&gt;Room Type&lt;/td&gt;";
    for (int x = 0; x &lt; bookingDates.Length; x++)
    {
        string[] bookingDay = bookingDates[x].Split('-');
        pricesHeader += "&lt;td align='center'&gt;" + bookingDays[x].Substring(0, 3) + "&lt;br&gt;" + bookingDay[2] + "&lt;/td&gt;";
    }
    pricesHeader += "&lt;td&gt;Persons&lt;/td&gt;&lt;/tr&gt;";
    string pricesContent = "&lt;tr&gt;";
    int dropNumber = 1;
    foreach (XmlElement node in prices)
    {
        XmlNodeList roomTypeDescriptionN = node.GetElementsByTagName("roomTypeDescription");
        string roomTypeDescriptionS = roomTypeDescriptionN[0].InnerText;
        pricesContent += "&lt;td&gt;" + roomTypeDescriptionS + "&lt;/td&gt;";
        XmlNodeList priceN = node.GetElementsByTagName("price");
        string priceS = priceN[0].InnerText;
        XmlNodeList currencyN = node.GetElementsByTagName("currency");
        string currencyS = currencyN[0].InnerText;
        if (currencyS == "EUR")
        {
            currencyS = "&amp;euro";
        }
        string avDates = "";
        XmlNodeList availableDatesN = node.GetElementsByTagName("date");
        int dateNumber = 0;
        foreach (XmlElement avDate in availableDatesN)
        {
            avDates += availableDatesN[dateNumber].InnerText + ",";
            dateNumber++;
        }

        for (int c = 0; c &lt; bookingDates.Length; c++)
        {
            if (avDates.Contains(bookingDates[c]))
            {
                pricesContent += "&lt;td&gt;" + priceS + currencyS + "&lt;/td&gt;";
            }
            else
            {
                pricesContent += "&lt;td&gt;&lt;center&gt;X&lt;/center&gt;&lt;/td&gt;";
            }
        }
        pricesContent += "&lt;td&gt;&lt;select runat=server name='pers" + dropNumber + "' id='pers" + dropNumber + "'&gt;" +
                      "&lt;option&gt;0&lt;/option&gt;&lt;option&gt;1&lt;/option&gt;&lt;option&gt;2&lt;/option&gt;&lt;option&gt;3&lt;/option&gt;&lt;option&gt;4&lt;/option&gt;&lt;option&gt;5&lt;/option&gt;&lt;option&gt;6&lt;/option&gt;&lt;option&gt;7&lt;/option&gt;&lt;option&gt;8&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;";
        dropNumber++;
    }
    pricesLabel.Text = pricesHeader + pricesContent + "&lt;/table&gt;";
</code></pre>

<p>I know that doing that and adding the runat=server won't help on my  control, there is where my main problem is now, how to add the code on the html to be able to get the dropdownlist selected value later with c#. Can I do that with Request.Form ? was trying but so far I couldnt do it.</p>
