title: Add <li> to <ul> tag from code behind C# ASP NET
body: <p>well how the title says, how can I add various <code>&lt;li&gt;</code> tags to a <code>&lt;ul&gt;</code> tag from code behind. I tried this <a href="https://stackoverflow.com/questions/3530965/add-to-list-from-codebehind-c-sharp-asp-net">Add to List from codebehind C# Asp.net</a> this is my example code.</p>
  
  <p>ASP</p>
  
  <pre><code>&lt;body&gt;
  &lt;form id="form1" runat="server"&gt;
  &lt;div&gt;
      &lt;ul id="menu" runat="server"&gt; &lt;/ul&gt;
  
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p></p>
  
  <p>And code behind.</p>
  
  <pre><code>        protected void Page_Load(object sender, EventArgs e)
      {
          CreateMenu();
  
  
      }
  
      protected void CreateMenu()
      {
          HtmlGenericControl li = new HtmlGenericControl("li");
          menu.Controls.Add(li);
  
          HtmlGenericControl anchor = new HtmlGenericControl("a");
          anchor.Attributes.Add("href", "login.aspx");
          anchor.InnerText = "login";
  
  
  
          li.Controls.Add(anchor);
      }
  </code></pre>
  
  <p>Well it works perfectly but maybe this gonna be a dumb question, how can I add more than one element to the <code>&lt;ul&gt;</code> tag? I need to create an new object for each item (I think this is wrong) or exist a better way to do this?</p>
  
  <p>I searched but any example satisfies my doubt, sorry if you think is a repeated question.</p>