我该怎么说 in the Repeater After 3 Replies

问题描述 投票:1回答:1

我想在3个回复/产品之后将<hr />放入转发器中。

这是我的转发器代码:

<asp:Repeater ID="RptrProduct" runat="server">
    <ItemTemplate>
        <figure class="span4 slide">
            <a href="#">
                <img src="<%#"/images/product/"+Eval("ProductImage")%>" alt="" class="pro-img" />
            </a>
            <span class="title" style="margin-left: 50px;"><a href="#"><%#Eval("ProductName") %></a></span>
        </figure>
    </ItemTemplate>
</asp:Repeater>

这是绑定转发器的.cs代码:

BL_Product blp = new BL_Product();
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        RptrProduct.DataSource = blp.ListProduct();
        RptrProduct.DataBind();
    }
}
c# asp.net class repeater
1个回答
2
投票

只需在数字标签关闭下方添加<% if ((Container.ItemIndex + 1) % 3 == 0) { %> <hr /><% } %>即可。

<asp:Repeater ID="RptrProduct" runat="server">
    <ItemTemplate>
        <figure class="span4 slide">
            <a href="#">
                <img src="<%#"/images/product/"+Eval("ProductImage")%>" alt="" class="pro-img" />
            </a>
            <span class="title" style="margin-left: 50px;"><a href="#"><%#Eval("ProductName") %></a></span>
        </figure>
        <% if ((Container.ItemIndex + 1) % 3 == 0) { %>
        <hr />
        <% } %>
    </ItemTemplate>
</asp:Repeater>
© www.soinside.com 2019 - 2024. All rights reserved.