<p>I have the following code, I'm trying to get a table with 4 columns across. If I run out of columns, create a new row and make 4 more coumns. rinse. lather. repeat.</p>

<pre><code>&lt;tbody&gt;
&lt;%
int i = 0;
foreach (ItmXtnMultimedia multimedia in ViewData.Model.ItmXtnMultimedia) {
  if (i%4 == 0 &amp;&amp; i== 0)
  {
    %&gt;&lt;tr&gt;&lt;%
  }
  if (i%4 == 0 &amp;&amp; i != 0)
  {
    %&gt;&lt;/tr&gt;&lt;tr&gt;&lt;%
  }
  %&gt;                    
  &lt;td&gt;&lt;%= multimedia.ImgTag100 %&gt;&lt;/td&gt;                            
  &lt;%
  i++;
  } %&gt;                    
</code></pre>

<p></p>

<p>It works, but it sucks. Is there something built in to the framework or an extension method I can use? I guess I could roll my own, but figured there had to be something out there.</p>

You should replace the second if with else if.. Other than that, it's okay.
```
```
foreach (ItmXtnMultimedia multimedia in ViewData.Model.ItmXtnMultimedia) 
{
  if (i%4 == 0 && i== 0)
  {
      %><tr><%
  }
  else if (i%4 == 0 && i != 0)
  {
      %></tr><tr><%
  }
  %><td><%= multimedia.ImgTag100 %></td><%
  i++;
}%>
```
```