I have read this excellent Multi-column list article, as well as this question on SO. I've come to the conclusion that there is no cross-browser way to turn a long unordered list into n columns of equal length. So far, I have been reduced to multiple-ul solutions like this:
//Three columns.
string col1 = string.Empty;
string col2 = string.Empty;
string col3 = string.Empty;
int currItem = 0;
int collectionCount = myItemCollection.Count;
foreach item in myItemCollection {
currItem++;
if (currItem < collectionCount * .33)
{
col1 = col1 + item.someProperty
}
else if (currItem < collectionCount * .67)
{
col2 = col2 + item.someProperty
}
else
{
col3 = col3 + item.someProperty
}
}
string allColumns = @"<ul>" + col1 + "</ul><ul>"
col2 + "</ul><ul>" + col3 + "</ul>";
Response.Write(allColumns);
Is there a simpler way to separate my list into groups of three, or better yet, to simply write the appropriate closing/starting ul tags when an element is the last item in a "third"?