title: ASP.NET Dynamic Control Addition
body: <p><strong>ORIGINAL POST</strong></p>
  
  <p>There are a <strong>ton</strong> of articles out there and a lot more questions than answers posted here on SO for my particular question.</p>
  
  <p>I have a web page that I'm creating that will have a DropDownList control of <em>products</em> a user can select from to enter into an <em>order</em> for processing. In addition to that there are two (2) other DropDownList controls that contain <em>options</em> and <em>accessories</em> for each particular <em>product</em>. I want the user to be able to enter in multiple <em>product</em> lines into the <em>order</em> object for processing along with corresponding <em>options</em> and/or *accessories. This will reduce the amount of records to store for customer information within the database.</p>
  
  <p>As the user is selecting from this DropDownList I would like to create a list of <em>products</em> but this list will have to be created dynamically based upon the number of <em>products</em> the user has to enter for a specific <em>order</em>. I understand the needs involved of saving the data as it is not automatically saved to the ViewState but having trouble figuring out how to push the data in the right direction.</p>
  
  <p>Should I be looking to use something other than ASP.NET to create my web page due to the complexities of dealing with the ViewState? While it may be complex, is there a better methodology to use when attempting such a course of action?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>So my findings are bringing me to believe that in order to store the data properly as it is being added I should be using a Repeater control and DataBind that to a Dictionary object containing my data in KeyValuePairs. I'm looking for a simplified way of doing this to instead just add directly an object that contains all data I would need. I can certainly add this class to the Repeater and DataBind to it but re-hydrating the data back out of the Repeater is causing me more than a few issues.</p>
  
  <pre><code>public class Order
  {
      public Order() { }
      public string CustomerNamer { get; set; }
      public ProductList ProductOrdered { get; set; }
  }
  public class ProductList : List&lt;Product&gt;
  {
       public ProductList() { }
  }
  public class Product
  {
       public Product() { }
       public int ID { get; set; }
       public string Name { get; set; }
       public string ProdcutCode { get; set; }
  }
  </code></pre>
  
  <p><strong>CODE BEHIND:</strong></p>
  
  <pre><code>protected void order_add_Click(object sender, EventArgs e)
  {
          Dictionary&lt;int, Order&gt; objOrders = new Dictionary&lt;int, Order&gt;();
  
          Order objOrder = new Order();
          Product objProduct = new Product();
  
          objProduct.Name = "Tire";
          objProduct.ProductCode = "75R15";
  
          objOrder.ProductsOrdered = new ProductList();
  
          objOrder.ProductsOrdered.Add(objProduct);
  
          objOrders.Add(0, objOrder);
  
          rptTest.DataSource = objOrders;
          rptTest.DataBind();
  }
  </code></pre>