title: StringBuilder html table from my class library class
body: <p>I have a class inside my class library that has a method which uses a list with a  <code>SqlDataReader</code> to cycle through all the records.</p>
  
  <pre><code>public List&lt;myDetails&gt; GetAddressDetails(int id)
  {
      List&lt;myDetails&gt; mydetails = new List&lt;myDetails&gt;();
      myDetails details;
  
      try
      {
          using (SqlDataReader rdr = cmd.ExecuteReader())
          {
              while (reader.Read())
              {
                  details = new myDetails((
                      reader.GetString(reader.GetOrdinal("FieldName")));
  
                  mydetails.Add(details);
          }
          rdr.Close();
          return mydetails;
      }
  }
  </code></pre>
  
  <p>I am trying to use a <code>StringBuilder</code> to build an HTML table, but having trouble figuring out how to loop through my list collection correctly. I tried a couple of different for loops but they were not giving the correct results.</p>
  
  <pre><code>    var item = clib.GetAddressDetails(Convert.ToInt32(Session["mysession"]));
  
          if (item != null)
          {      
              StringBuilder htmlStr = new StringBuilder("");
              htmlStr.Append("&lt;center&gt;&lt;h2 class='headings'&gt;Addresses&lt;/h2&gt;");
              htmlStr.Append("&lt;table border='1' cellpadding='3'&gt;");
  
  foreach (var detail in item)
  {
              htmlStr.Append("&lt;tr&gt;");
              htmlStr.Append("&lt;td width='25px'&gt;" + item.FieldName + "&lt;/td&gt;&lt;tr&gt;");
              htmlStr.Append("&lt;/tr&gt;");
              htmlStr.Append("&lt;/table&gt;&lt;/center&gt;&lt;br/&gt;");
              divAddresses.InnerHtml = htmlStr.ToString();   
      }
  
  
          }
  </code></pre>