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 9124279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:32:12+00:00 2026-06-17T06:32:12+00:00

I am creating a dynamic form where a user selects an area then a

  • 0

I am creating a dynamic form where a user selects an area then a topic, then based on the topic a set of controls will load. The options for the form are all defined in an XML file.

My issues is that when I am traversing the XML I am getting down to the defined controls which I have 2 in the text file I made it is creating each control twice. I think it would be better to show some code then explain so here is my code.

 <?xml version="1.0" encoding="utf-8" ?>
 <options>
  <option name="xerox">
   <sub_option name="Paper Jam">
    <input type="dropdown" name="location" />
    <input type="textbox" name="printername" />
   </sub_option>
   <sub_option name="New Printer Request" />
   <sub_option name="Supply Request" />
   <sub_option name="Hardware Failure" />
 </option>
</options> 

And the C# code below

 protected void loadControls(string parent, string parentNode)
    {
        XmlDocument itemList = new XmlDocument();
        itemList.Load(@"c:\inetpub\wwwroot\sp\css\itemList.xml");
        Panel controls = new Panel();
        XmlNodeList nodeList = itemList.SelectNodes("options/child::node()");
        test.Text = parent;
        foreach (XmlNode node in nodeList)
        {
            if (node.Attributes["name"].Value == parentNode && node.HasChildNodes)
            {
                test.Text = "for 2 coming";
                foreach (XmlNode subnode in node.ChildNodes)
                {
                    if (subnode.Attributes["name"].Value == parent && subnode.HasChildNodes)
                    {
                        foreach (XmlNode optionNode in subnode.ChildNodes)
                        {

                            string controlType = optionNode.Attributes["type"].Value;
                            string controlName = optionNode.Attributes["name"].Value;
                            switch(controlType)
                            {
                                case "dropdown":
                                    DropDownList ddl = new DropDownList();
                                    qna.Controls.Add(ddl);
                                    break;
                                case "textbox":
                                    TextBox tb = new TextBox();
                                    qna.Controls.Add(tb);
                                    break;       
                            }

                        }
                    }
                }
            }


        }

Output below(this is after selecting Paper Jam)
output

  • 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-06-17T06:32:13+00:00Added an answer on June 17, 2026 at 6:32 am

    I guess the issue is in your below code lines:

    test.Text = "for 2 coming";
    foreach (XmlNode subnode in node.ChildNodes)
    {
    

    You should check the following instead of foreach loop here

    if(node.ChildNodes.Count>0)
    {
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an dynamic controls I have an drop down with options Textbox,
I am creating dynamic text boxes on button click and then showing values on
Was wondering if anyone had any smart approaches to creating dynamic vanity user urls
Hi there i want to create a dynamic functionality like creating dynamic form in
This Is my Html Form by which i m creating a form and dynamic
I am creating a dynamic form in Access 2003. Each time the form is
I am creating a dynamic form similar to what is wanted here . Well
I'm creating a dynamic form builder where table rows can be dragged, dropped, reordered
I have a form that will have dynamic elements inserted with javascript and am
I'm creating a dynamic button and generating a signature based on the doc and

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.