How do you show x items per row in a repeater?

2020-02-06 08:10发布

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>

标签: asp.net
7条回答
萌系小妹纸
2楼-- · 2020-02-06 08:39

Using DataList control with RepeatColumns property might be simpler :

DataList1.RepeatColumns = 4;
DataList1.RepeatDirection = RepeatDirection.Horizontal;
查看更多
登录 后发表回答