ASP: resulting recordset in two columns

Today I am going to show you a little trick: how to display your recordset data in two columns. And to do so, we will use the MOD remainder function.
Let me make things more clear. We assume we are getting data from a database consisting in a single column recordset. Something like:

Name 1
Name 2
Name 3
Name 4
Name 5

Regardless the number of rows, what we want is to display data the following way:

Name 1Name 2
Name 3Name 4
Name 5

How do we do it? Believe me it is very simple.
Some background
First of all let me tell you that if you follow the examples in this post, you will be able to manipulate data in every way you like. You will be able to create tables with any number of columns (even or odd). It is just a matter of understanding the basics that I will explain here.
In order to achieve our goal, we are going to use the MOD function.

The MOD function
The MOD function provides the remainder value in a division. The remainder is what's left over after you do a division:
10 / 2 = 5, remainder 0
18 / 5 = 3, remainder 3
20 / 3 = 6, remainder 2
In ASP, we use the MOD function as if two values are compared:
remainder_value = val1 MOD val2
What is the remainder_value in the following example?
Dim remainder_value
Dim val1
Dim val2
val1 = 10
val2 = 3
remainder_value = val1 MOD val2
The answer is 1.

The table
Just to begin, we will assume some things. First of all, our recordset is RS (wow that's new, isn't it?). Second: we have a repeat region and we set a variable for the number of rows (numRows) to 1, outside our repeat region.
Let's start building our table:

               
                 
                 
                The table has width = 100% (the other properties are obviously customizable to your needs). As you can see we have already create a dummy row with two columns. Now the first tricky part:
               

                 
"%>
                  <%end if%>
Here we start with a new row (And then again, we check the closing tags:
                  <%If numRows MOD 2 = 0 then%>
                  <%response.write "
<%
While ((numRows <> 0) AND (NOT RS.EOF))
%>
                  <%If numRows MOD 2 <> 0 then%>
                  <%response.write "
) and start the repeat region (While). Then, if the number of rows / 2 has a remainder not equal to zero, we close the row. Following the repeat region:
numRows = 1 / 2, remainder <> 0
numRows = 2 / 2, remainder = 0
numRows = 3 / 2, remainder <> 0
numRows = 4 / 2, remainder = 0
And so on.
Now, we create the main container:


                     
                       
                     
<%=(RS.Fields.Item("name").value)%>

"%>
                  <%end if%>
                  <%
  numRows=numRows+1
  RS.MoveNext()
Wend %>
Basically, we close the row when the numRows MOD 2 is equal to zero. Outside the repeat region, we close the table tag. And the result is what we were looking for.
As an exercise, think about doing the same for 3 columns table. If you can't find the solution, please ask and I might publish a new post with the solution.