MaxRecursion MaxRecursion - 4 months ago 53
ASP.NET (C#) Question

Repeatcolumn property of DataList

I am using a DataList to render some divs in table layout and RepeatColumn property set to 3.
when my datasource has 3 or more than 3 records it works correctly and renders 3 columns and as many required rows.
But when my datasource contains one or two records it renders only one or two columns respectively, so violating standard of site.
Is there any way of padding so that if my datasource contains one record then other two columns will be generated automatically(of-course empty) or if datasource contains two records then third column will be generated automatically.


Just make sure you always have at least three items in your datasource before you bind it.

Some psuedo-code should suffice:

datasource = GetDatasourceMethod();
while(datasource.Count <= 3) {
datalist.DataSource = dataSource;