How to hide() first element in a <asp:repeater>

限于喜欢 提交于 2019-12-11 18:51:29

问题


This is my code :

<asp:Repeater runat="server" ID="rpUbicazione">
    <ItemTemplate>
        <div class="Field" style="margin-bottom:20px;">
            // elements
        </div>
    </ItemTemplate>
</asp:Repeater>

and I'd like to hide first element. So I tried changing first line with :

<asp:Repeater runat="server" ID="rpUbicazione" Visible="<%# (Container.ItemIndex != 0) %>">

but seems it doesnt works : ItemIndex it is not a method.

How can I do it?


回答1:


Try this:

<asp:Repeater runat="server" ID="rpUbicazione">
    <ItemTemplate>
        <div class="Field" style='margin-bottom: 20px; display: <%# Container.ItemIndex == 0 ? "none" : "block"  %>'>
            // elements
        </div>
    </ItemTemplate>
</asp:Repeater>

or you can do something like this:

<script runat="server">
    protected void rpUbicazione_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemIndex == 0)
        {
            e.Item.FindControl("divElement").Visible = false;
        }
    }
</script>

<asp:Repeater runat="server" ID="rpUbicazione" onitemdatabound="rpUbicazione_ItemDataBound">
    <ItemTemplate>
        <div id="divElement" runat="server" class="Field" style="margin-bottom: 20px;">
            // elements
        </div>
    </ItemTemplate>
</asp:Repeater>


来源:https://stackoverflow.com/questions/9363715/how-to-hide-first-element-in-a-asprepeater

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!