Note that there are some explanatory texts on larger screens.

plurals
  1. POforeach loop to retrieve list items and create a table
    primarykey
    data
    text
    <p>I am a little confused as to how to display list data in two columns in a webpart.</p> <p>Here is what i have at the moment (Webpart):</p> <pre><code>&lt;table width="100%"&gt; &lt;tr&gt; &lt;td width="50%"&gt; &lt;asp:PlaceHolder ID="PlaceHolder1" runat="server"&gt;&lt;/asp:PlaceHolder&gt; &lt;/td&gt; &lt;td width="50%"&gt; &lt;asp:PlaceHolder ID="PlaceHolder2" runat="server"&gt;&lt;/asp:PlaceHolder&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>and the code behind for it is the following:</p> <pre><code>foreach (SPListItem oListItem in listItemCollection) { awardYear = oListItem["Year"].ToString(); awardCategory = oListItem["Category"].ToString(); awardOrganiser = oListItem["Organiser"].ToString(); //awardNomWon = oListItem["NominatedWon"].ToString(); //not yet needed //need to fingure out how to display images: //awardLogo = oListItem["Logo"].ToString(); //string mydatetime; //mydatetime = new DatTime(awardYear).ToString; //DateTime convertedaValue = DateTime.Parse(awardYear); //string awardYearConverted = convertedaValue.ToString(); PlaceHolder1.Controls.Add( new LiteralControl(awardYear + " " + "|" + "&lt;br/&gt; " + awardCategory + " " + "|" + "&lt;br/&gt; " + awardOrganiser + " " + "|" + "&lt;br/&gt;&lt;br/&gt;")); PlaceHolder2.Controls.Add( new LiteralControl(awardYear + " " + "|" + "&lt;br/&gt; " + awardCategory + " " + "|" + "&lt;br/&gt; " + awardOrganiser + " " + "|" + "&lt;br/&gt;&lt;br/&gt;")); /* PlaceHolder2.Controls.Add( new LiteralControl("&lt;table&gt;&lt;tr&gt;&lt;td&gt;" + awardYear + "&lt;/td&gt;" + "&lt;td&gt;&amp;#160;&lt;/td&gt;" + "&lt;td&gt;" + awardCategory + "&lt;br/&gt;" + awardOrganiser + "&lt;/td&gt;&lt;/tr&gt;" )); */ } </code></pre> <p>What I am trying to achieve is to write the details from an "Awards" list and display them in two columns. Currently everything works, but the problem is that data is being repeated in colum1 and column2 of the table. Ideally I was hoping that the "foreach" will create the table and populate it with the details from the list.</p> <p>There maybe something that I have missed, but I can't really see what that could be. Any suggestions will be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload