Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

asp.net - How do you show x items per row in a repeater?

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...