Anyone have any clue on how to show 4 items going horizontal with a repeater? A repeater shows items going down by default. Here is my test repeater code so far:
<table border=0 cellpadding=0 cellspacing=0 align="center" width="800px;>
<tr>
<asp:Repeater ID="rptTest" runat="server">
<ItemTemplate>
<td>
<h3><a href="<%#GetItemLink((Item)Container.DataItem) %>"><%#((WebMenuItem)Container.DataItem).Name %></a></h3>
<div>
<a href="<%#GetUrl((Item)Container.DataItem) %>">
<img src="<%#GetImage((Item)Container.DataItem) %>" alt="<%#GetAltText((Item)Container.DataItem) %>" />
</a>
</div>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
</table>
<table>
<asp:Repeater id="rptTest" runat="server">
<ItemTemplate>
<%# (Container.ItemIndex + 4) % 4 == 0 ? "<tr>" : string.Empty %>
<td>
... cell contents omitted ...
</td>
<%# (Container.ItemIndex + 4) % 4 == 3 ? "</tr>" : string.Empty %>
</ItemTemplate>
</asp:Repeater>
</table>
Long live the humble repeater!
Modifying Nick's suggestion I was able to use to make a 5 horizontal x n vertical Image Grid. Thanks Nick!
<asp:Repeater ID="colorsList" runat="server">
<HeaderTemplate>
<table>
<tr>
</HeaderTemplate>
<ItemTemplate>
<%# (Container.ItemIndex != 0 && Container.ItemIndex % 5 == 0) ? @"</tr><tr>" : string.Empty %>
<td>
<div><img src="<%#ColorThumbnailImage((string)DataBinder.Eval(Container.DataItem, "COLOR_SQUARE_IMAGE")) %>" /></div>
<div><%# DataBinder.Eval(Container.DataItem, "COLOR_NAME") %></div>
</td>
</ItemTemplate>
<FooterTemplate>
</tr></table>
</FooterTemplate>
</asp:Repeater>
And here's ColorThumbnailImage
protected string ColorThumbnailImage(string fileName)
{
return Request.ApplicationPath + MySports.System.Configuration.ColorSquareImageLocation + fileName;
}
Scott Guthrie provided an example of how to do this with a ListView control in the following article. He uses the control to render an unordered list and uses CSS to control the layout.
Using DataList control with RepeatColumns property might be simpler :
DataList1.RepeatColumns = 4;
DataList1.RepeatDirection = RepeatDirection.Horizontal;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With