title: Programmatically Creating fieldset, ol/ul and li tags in ASP.Net, C#
body: <p>I need to write an ASP.Net form which will produce the following HTML:</p>
  
  <pre><code>&lt;fieldset&gt;   
  &lt;legend&gt;Contact Details&lt;/legend&gt;   
  &lt;ol&gt;   
  &lt;li&gt;   
  &lt;label for="name"&gt;Name:&lt;/label&gt;   
  &lt;input id="name" name="name" class="text" type="text" /&gt;   
  &lt;/li&gt;   
  &lt;li&gt;   
  &lt;label for="email"&gt;Email address:&lt;/label&gt;   
  &lt;input id="email" name="email" class="text" type="text" /&gt;   
  &lt;/li&gt;   
  &lt;li&gt;   
  &lt;label for="phone"&gt;Telephone:&lt;/label&gt;   
  &lt;input id="phone" name="phone" class="text" type="text" /&gt;   
  &lt;/li&gt;   
  &lt;/ol&gt;   
  &lt;/fieldset&gt;  
  </code></pre>
  
  <p>However, the fields which are to be added to the form will be determined at runtime, so I need to create the fieldset at runtime and add an ordered list and listitems to it, with labels, textboxes, checkboxes etc as appropriate.</p>
  
  <p>I can’t find standard ASP.Net objects which will create these tags.</p>
  
  <p>For instance, I’d like to do something like the following in C#:</p>
  
  <pre><code>FieldSet myFieldSet = new FieldSet();
  myFieldSet.Legend = “Contact Details”;
  OrderedList myOrderedList = new OrderedList();
  
  ListItem listItem1 = new ListItem();
  ListItem listItem2 = new ListItem();
  ListItem listItem3 = new ListItem();
  
  // code here which would add labels and textboxes to the ListItems
  
  myOrderedList.Controls.Add(listItem1);
  myOrderedList.Controls.Add(listItem2);
  myOrderedList.Controls.Add(listItem3);
  
  myFieldSet.Controls.Add(myOrderedList);
  
  Form1.Controls.Add(myFieldSet);
  </code></pre>
  
  <p>Are there any standard ASP.Net objects which can produce this, or is there some other way of achieving the same result?</p>
  
  <p>Matt</p>