如何在转发器

时间:2016-03-28 14:29:09

标签: html css asp.net repeater

中继器:

<asp:Repeater ID="repeater" runat="server">
    <ItemTemplate>
        <%# Container.ItemIndex % 2 == 0 %>
        <div class="class1">
            <span style="float: left;">
                <img src="" />
            </span>
            <span style="float: right;">
                <asp:Label id="lFN" runat="server" />
            </span>
        </div>
        <%# Container.ItemIndex % 2 != 0 %>
        <div class="class2">
            <span style="float: right;">
                <img src="" />
            </span>
            <span style="float: left;">
                <asp:Label id="lFN2" runat="server" />
            </span>
        </div>
    </ItemTemplate>
</asp:Repeater>

我想为替代项目做的是显示class2 div。

像这样的结果:

<div class="class1"> //index 0
    <span style="float: left;">
        <img src="myimg.jpg" />
    </span>
    <span style="float: right;">
        <span>John</span>
    </span>
</div>
<div class="class2"> //index 1
    <span style="float: right;">
        <img src="myimg2.jpg" />
    </span>
    <span style="float: left;">
        <span>Mike</span>
    </span>
</div>
<div class="class1"> //index 2
    <span style="float: left;">
        <img src="myimg3.jpg" />
    </span>
    <span style="float: right;">
        <span>Quentin</span>
    </span>
</div>
...

我如何实现上述目标?

我现在的方式就是显示TRUE FALSE并多次显示记录。

1 个答案:

答案 0 :(得分:2)

<asp:Repeater ID="repeater" runat="server">
    <ItemTemplate>

        <div class='<%# Container.ItemIndex % 2 == 0 ? "class1" : "class2" %>'>
            <span style='<%# Container.ItemIndex % 2 == 0 ? "float:left;" : "float:right;" %>'>
                <img src='<%# Eval("ProfilePic") %>' />
            </span>
            <span style='<%# Container.ItemIndex % 2 == 0 ? "float:right;" : "float:left;" %>'>
                <asp:Label id="lFN" runat="server" Text='<%# Eval("Name") %>' />
            </span>
        </div>

    </ItemTemplate>
</asp:Repeater>