title: Displaying list items in a table programatically
body: <p>I have the following code so far which displays list items from a list (using custom web parts properties to obtain the list url and list name).</p>
  
  <p>Code to display list item:</p>
  
  <pre><code>if(this.WebPart.ListUrl != null &amp;&amp; this.WebPart.ListName != null &amp;&amp; 
  this.WebPart.AwardYear != null)
  {
  
  
  //getting custom properties values
  string listURL = this.WebPart.ListUrl.ToString();
  string listName = this.WebPart.ListName.ToString();
  string awardYear = this.WebPart.AwardYear.ToString();
  
  
  using (SPSite site = new SPSite(listURL))
  {
  
  using (SPWeb web = site.OpenWeb())
  {
  
  try
  {
  
  
   SPList list = web.Lists[listName]; //name of the list
  
  
   //CAML query to filter list items by year and then order by year in descending order
   SPQuery awardsYear = new SPQuery();
   awardsYear.Query = @"&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name='Year'/&gt;&lt;Value Type='Text'&gt;" + 
   awardYear + @"&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;" + "&lt;OrderBy&gt;&lt;FieldRef Name='Year' 
   Ascending='False' /&gt;&lt;/OrderBy&gt;";
  
  
   SPListItemCollection listItemColl = list.GetItems(awardsYear);
  
  
   //code for generating the table goes here EXPERIMENTAL
   Table table1 = new Table();
   TableRow tableRow = new TableRow();
   TableCell tableCell = new TableCell();
  
  
  
   int numberOfColumns = 4; //number of columns for the chambers table
   for (int x = 0; x &lt; numberOfColumns; x++)
   {
  
   //Table columns created here need to be added somehow to the table above
  
  
   }
  
  
  
   //getting all the list items in the list and displaying them
   foreach (SPListItem listItem in listItemColl)
   {
  
    //For each of the list items create the table rows
  
  
  
  
  
  
    //The below needs to be put into a table generated programatically
    chambers = listItem["Title"].ToString();
    band = listItem["Band"].ToString();
    peopleRecommended = listItem["PeopleRecommended"].ToString();
    band2 = listItem["Band2"].ToString();
  
    //placeholders used to display the results
    plhDirRankings.Controls.Add(new LiteralControl("Chambers: " + chambers + "&lt;br/&gt;"));
    plhDirRankings.Controls.Add(new LiteralControl("Band: " + band + "&lt;br/&gt;"));
    plhDirRankings.Controls.Add(new LiteralControl("People Recommended: " + 
    peopleRecommended + "&lt;br/&gt;"));
    plhDirRankings.Controls.Add(new LiteralControl("Band: " + band2 + "&lt;br/&gt;"));
  
  
    }
  
  
  
    }
  
    catch (Exception err)
    {
  
    plhDirRankings.Controls.Add(new LiteralControl(err.ToString()));
  
    }
  
    }
  
    }
  
    }
  </code></pre>
  
  <p>what's the easiest way to generate a generate a table programmatically to display the list items as follows:</p>
  
  <pre><code>Chambers | Band  | PeopleRecommended | Band2 
  --------------------------------------------
  item1    | item1 | item1             | item1
  item2    | item2 | item2             | item2
  </code></pre>
  
  <p>I haven't done much with creating tables programatically before so I am a little confused. I have started some of the code for the table to get me thinking but haven't managed to put it together.</p>
  
  <p>Any assistance on this or perhaps a link to a good tutorial would be greatly appreciated</p>
  
  <p>Many Thanks,</p>