MaxRecursion MaxRecursion - 1 year ago 138
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.

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download