Pregunta

Este es mi código:

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

Y me gustaría esconder el primer elemento. Así que intenté cambiar la primera línea con:

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

pero parece que no funciona: ItemIndex No es un método.

¿Cómo puedo hacerlo?

¿Fue útil?

Solución

Prueba esto:

<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>

O puedes hacer algo como esto:

<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>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top