Creating an HTML table in C# with a new row ever 4 elements?
<p>This is very simple, but I'm being rather stupid about it. I have a list of elements and I need to create a new row after the 4th element. So say I have a list "One, Two, Three, Four, Five, Six" ... the resulting HTML table needs to look like this:</p>

<pre><code>+-------------------------+
| One | Two | Three | Four|
+-------------------------+
| Five| Six |       |     |
+-------------------------+
</code></pre>

<p>If I were using Javascript it'd be very, very clean, something like this:</p>

<pre><code>for (var i = 0; &lt;= (Items.length - 1); i++) {
if ((i%5) === 0) {
   $("#myTable").append('&lt;tr class="table-rows" /&gt;');
   $("#myTable .table-rows:last").append(Items[i]);
}
 else {
   $("#myTable .table-rows:last").append(Items[i]);
}
</code></pre>

<p>Well that code might not exactly work, but I'd use the modulo operator to determine when to create a new row then append the data.</p>

<p>You might say that I shouldn't be using a table for this, and I would agree, but this is not the requirement I'm working under. You might also say that it'd be easier to build the table server side (I'm using ASP.NET MVC, so in a controller), but I have to do this in a view that's inheriting List as its model.</p>

<p>I really want to break up the items into groups of 4 (again this is ugly code, and I'm omitting the ugly WebForms viewengine markup for clarity):</p>

<pre><code>for (int i = 0; i &lt; Model.Count; i = i + 4) {
&lt;tr&gt;
 &lt;td&gt;Model[i]&lt;/td&gt;
 &lt;td&gt;i + 1 &lt; Model.Count ? Model[i + 1] : ""&lt;/td&gt;
 &lt;td&gt;i + 2 &lt; Model.Count ? Model[i + 2] : ""&lt;/td&gt;
 &lt;td&gt;i + 3 &lt; Model.Count ? Model[i + 3] : ""&lt;/td&gt;
&lt;/tr&gt;
}
</code></pre>

<p>This works for the first set of 4, but then each element gets its own row:</p>

<pre><code>+-------------------------+
| One | Two | Three | Four|
+-------------------------+
| Five|     |       |     |
+-------------------------+
| Six |     |       |     |
+-------------------------+
</code></pre>

<p>I feel as if I'm oh so close, what gives?</p>
