Data display question

  • Thread starter Thread starter Alex Greenberg
  • Start date Start date
A

Alex Greenberg

Hi,

I don't know if I'm doing anything wrong, but I'm trying to list 3
products per line on a page. So for example, if a user searches for
'widget' and he gets 4 results, I would have something like:

w1 w2 w3
w1 info w2 info w3 info
---------- ------------ -----------
w4
w4 info
----------

I'm using a DataList control, with <ItemTemplate> something like:
<table>
<tr><td>name</td></tr>
<tr><td>info</td></tr>
</table>

the problem is that the products are not lining up, for the obvious
reason that the DataList control is putting each product in its own
table. Specifying the height of the table or its rows doesn't help.

Obviously, what I need is a control that can put the names of the
products in the first row, and the info in the second row, then the
second set of products (4-6) in the third and fourth rows, and so on.

I don't know if the repeater can accomplish that. It just doesn't make
sense to use it, since it will only be able to put one item per row
(right?).

Should I just create my own table and iterate through the products,
filling it up as I go? or is there a better solution?

Thanks,

Alex
 
Alex,

The solution is to put the datalist inside another table and make the items
into the table cells.

<table><tr>
<asp:DataList>
<asp:ItemTemplate>
<td><table width="100%">
<tr><td>name</td></tr>
<tr><td>info</td></tr>
</table></td>
<asp:ItemTemplate>
<asp:SeparatorTemplate>
</tr><tr>
</asp:SeparatorTemplate>
</asp:DataList>
</tr></table>

Eliyahu
 
Actually, the separator template in this case has to be a bit more
sophisticated. You will want to render </tr><tr> after every third item
rather than after each one. The way of doing that is handle ItemDataBound
event to catch the items with ItemType = Separator and to make the separator
template generate </tr><tr> only for every third separator.

Eliyahu
 
Thanks Eliyahu,

Although this solution clearly works, I'm opting for the table-looping
solution. I'm not sure which is faster though. I will try both and
see.

Regards,

Alex
 
Back
Top