Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3492264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:44:15+00:00 2026-05-18T11:44:15+00:00

I’m trying to do this and it is a bit confusing for me. Basically

  • 0

I’m trying to do this and it is a bit confusing for me.

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.

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

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

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

The last column on the screenshot

https://i.stack.imgur.com/37chw.png

Update:

I’m creating the code from the xml results as a string that will print as html 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 < 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 = "<table width='100%'>";
    pricesHeader += "<tr><td>Room Type</td>";
    for (int x = 0; x < bookingDates.Length; x++)
    {
        string[] bookingDay = bookingDates[x].Split('-');
        pricesHeader += "<td align='center'>" + bookingDays[x].Substring(0, 3) + "<br>" + bookingDay[2] + "</td>";
    }
    pricesHeader += "<td>Persons</td></tr>";
    string pricesContent = "<tr>";
    int dropNumber = 1;
    foreach (XmlElement node in prices)
    {
        XmlNodeList roomTypeDescriptionN = node.GetElementsByTagName("roomTypeDescription");
        string roomTypeDescriptionS = roomTypeDescriptionN[0].InnerText;
        pricesContent += "<td>" + roomTypeDescriptionS + "</td>";
        XmlNodeList priceN = node.GetElementsByTagName("price");
        string priceS = priceN[0].InnerText;
        XmlNodeList currencyN = node.GetElementsByTagName("currency");
        string currencyS = currencyN[0].InnerText;
        if (currencyS == "EUR")
        {
            currencyS = "&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 < bookingDates.Length; c++)
        {
            if (avDates.Contains(bookingDates[c]))
            {
                pricesContent += "<td>" + priceS + currencyS + "</td>";
            }
            else
            {
                pricesContent += "<td><center>X</center></td>";
            }
        }
        pricesContent += "<td><select runat=server name='pers" + dropNumber + "' id='pers" + dropNumber + "'>" +
                      "<option>0</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option></select></td></tr>";
        dropNumber++;
    }
    pricesLabel.Text = pricesHeader + pricesContent + "</table>";

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:44:15+00:00Added an answer on May 18, 2026 at 11:44 am

    You can use List for saving your created dropdownlists. On submit, you can read the data from your list.

    List<DropDownList> ddlList = new List<DropDownList>{};
    for(int i=0;i<count;i++)
    {
        //add control to page
        ddlList.items.add(YourNewlyCreatedDdl);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.