title: Dynamically creating DIVs from Database in ASP.NET
body: <p>It is a beginner question. I want to create divs dynamically from database (<strong>MSSQL</strong>). For example, i want to show comments below an entry. The <strong>Comment</strong> table connected with <strong>Entry</strong> table by <strong>EntryID</strong>. My aspx code is like:    </p>
  
  <pre><code>&lt;div class="commentBody" runat="server"&gt;
        &lt;asp:Label ID="commentSender" runat="server" Text=""&gt;&lt;/asp:Label&gt;
        &lt;asp:Label ID="commentDate" runat="server" Text=""&gt;&lt;/asp:Label&gt;
        &lt;asp:Label ID="commentText" runat="server" Text=""&gt;&lt;/asp:Label&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This will be repeat for all comments. And I am working all codebehind (without evals). My c# code:</p>
  
  <pre><code>protected void YorumlariGetir()
  {   
      string selectComments = "SELECT * FROM Comment WHERE Comment.EntryID = @EntryID";
  
      SqlConnection conn = new SqlConnection(constr);
      SqlCommand cmd = new SqlCommand(selectComments, conn);
  
      cmd.Parameters.AddWithValue("@EntryID", Session["EntryID"].ToString());
  
      try
      {
          conn.Open();
          // HERE I WANT TO CALL A LOOP FOR COMMENTS
  
      }
      catch (Exception ex)
      {
          Response.Write("Hata: " + ex.Message);
      }
      finally
      {
          conn.Close();
      }
  }
  </code></pre>
  
  <p>I can use repeaters or foreach loop. But i don't know how and need an example at this point. </p>
  
  <p>Thanks for help.</p>