locked
Use if statement of repeater in repeater RRS feed

  • Question

  • User1351150732 posted

    I have 2 nested repeaters. I can't use the eval on the first repater in the second repeater if statement. I want to compare Repeater1 Eval and Repeater2 Eval in the Repeater2 ItemTemplate. How can I do that? Thank you for help. Here's an example:

    <asp:Repeater ID = "Repeater1" runat="server"  OnItemDataBound="Repeater1_ItemDataBound">
    <ItemTemplate>
        <asp:Repeater ID = "Repeater2" runat="server">
            <ItemTemplate>
            <% if (Repeater1Eval == Repeater2Eval) { %>
                    //Show Something
            <% } else { %>
                    //Show Something
            <% } %>
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
    </asp:Repeater>

    Saturday, February 24, 2018 4:51 PM

Answers

  • User283571144 posted

    Hi balamir,

    I have 2 nested repeaters. I can't use the eval on the first repater in the second repeater if statement. I want to compare Repeater1 Eval and Repeater2 Eval in the Repeater2 ItemTemplate. How can I do that? Thank you for help. Here's an example:

    According to your description, I suggest you could try to use below codes to achieve your requirements.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"  OnItemDataBound="OnItemDataBound">
                    <ItemTemplate>
                        <asp:Label ID="lblOrderId" runat="server" Text='<%#  Eval("username")  %>' />
                    </ItemTemplate>
                    <ItemTemplate>
                        <asp:Repeater ID="Repeater2" runat="server">
                            <ItemTemplate>
                                 <%# Eval("username").ToString() == (((RepeaterItem)Container.Parent.Parent).DataItem as System.Data.DataRowView)["username"].ToString() ? "Same username as Parent" : ""  %>
                            </ItemTemplate>
                        </asp:Repeater>
                    </ItemTemplate>
                </asp:Repeater>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:xxxxxxConnectionString %>" SelectCommand="SELECT * FROM [Persons]"></asp:SqlDataSource>
            </div>
        </form>
    </body>
    </html>
    

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 26, 2018 9:17 AM

All replies

  • User283571144 posted

    Hi balamir,

    I have 2 nested repeaters. I can't use the eval on the first repater in the second repeater if statement. I want to compare Repeater1 Eval and Repeater2 Eval in the Repeater2 ItemTemplate. How can I do that? Thank you for help. Here's an example:

    According to your description, I suggest you could try to use below codes to achieve your requirements.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"  OnItemDataBound="OnItemDataBound">
                    <ItemTemplate>
                        <asp:Label ID="lblOrderId" runat="server" Text='<%#  Eval("username")  %>' />
                    </ItemTemplate>
                    <ItemTemplate>
                        <asp:Repeater ID="Repeater2" runat="server">
                            <ItemTemplate>
                                 <%# Eval("username").ToString() == (((RepeaterItem)Container.Parent.Parent).DataItem as System.Data.DataRowView)["username"].ToString() ? "Same username as Parent" : ""  %>
                            </ItemTemplate>
                        </asp:Repeater>
                    </ItemTemplate>
                </asp:Repeater>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:xxxxxxConnectionString %>" SelectCommand="SELECT * FROM [Persons]"></asp:SqlDataSource>
            </div>
        </form>
    </body>
    </html>
    

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 26, 2018 9:17 AM
  • User1351150732 posted

    Thank you so much for your help!

    Monday, February 26, 2018 9:58 AM