Bind (Populate) N-Level nested Repeater using C# and VB.Net in ASP.Net

Last Reply 5 months ago By dharmendr

Posted 5 months ago

Dear Team,

I need help regarding binding of Nested Repeater.

Repeter RptrMyMenuSide & RptrMyMenuSideSub binding successfully.

but RptrMyMenuSideSubSub giving error object not reference not able to find control, beow is the code,

please help if i doing something wrong.

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            CategoriesSideMenu()
            ProductSideMenuSub()
            ProductSideMenuSubSub()
        End If
    End Sub
    Public Sub CategoriesSideMenu()
        RptrMyMenuSide.Visible = True
        cls.bindrepeter(RptrMyMenuSide, "Select CATID,CATNAME from CATEGORY ORDER BY CATORDER")

    End Sub
    Public Sub ProductSideMenuSub()
        For i As Integer = 0 To RptrMyMenuSide.Items.Count - 1
            Dim id As Label = DirectCast(RptrMyMenuSide.Items(i).FindControl("lblcatid"), Label)
            Dim RptrMyMenuSideSub As Repeater = DirectCast(RptrMyMenuSide.Items(i).FindControl("RptrMyMenuSideSub"), Repeater)
            cls.bindrepeter(RptrMyMenuSideSub, "Select SubCatId,SubCatName from SubCategoryMaster  WHERE CategoryId=" & id.Text & " ORDER BY SubCatOrder")
        Next
    End Sub
    Public Sub ProductSideMenuSubSub()
        For i As Integer = 0 To RptrMyMenuSide.Items.Count - 1
            Dim id As Label = DirectCast(RptrMyMenuSide.Items(i).FindControl("lblsubcatid"), Label)
            Dim RptrMyMenuSideSubSub As Repeater = DirectCast(RptrMyMenuSide.Items(i).FindControl("RptrMyMenuSide_RptrMyMenuSideSub"), Repeater)
            cls.bindrepeter(RptrMyMenuSideSubSub, "Select PRODUCTID,PRODUCTNAME from PRODUCT  WHERE PRODUCTCATID=" & id.Text & " ORDER BY PRODUCTCATID,PRODUCTNAME")
        Next
    End Sub
    Public Function bindrepeter(ByVal objRepeater As Object, ByVal Qry As String) As DataSet
            Dim con As New SqlConnection
            con.ConnectionString = ConfigurationManager.ConnectionStrings("conString").ConnectionString
            Dim ds As DataSet
            Dim adp As New SqlDataAdapter(Qry, con)
            ds = New DataSet()
            adp.Fill(ds)
            objRepeater.DataSource = ds
            objRepeater.DataBind()
            con.Close()
            Return ds
        End Function

 

<asp:Repeater ID="RptrMyMenuSide" runat="server" EnableTheming="True">
    <ItemTemplate>
        <asp:Label ID="lblcatid" runat="server" Text='<%# Eval("CATID") %>' Visible="true"></asp:Label>
        <li id="menu-item-<%# Eval("CATID")%>" class="menu-item-<%# Eval("CATID")%>"><a>
            <%# Eval("CATNAME")%></a>
            <asp:Repeater ID="RptrMyMenuSideSub" runat="server" EnableTheming="True">
                <ItemTemplate>
                    <ul class="sub-menu">
                        <asp:Label ID="lblsubcatid" runat="server" Text='<%# Eval("SubCatId") %>' Visible="true"></asp:Label>
                        <li id="menu-item-<%# Eval("SubCatId") %>" class="menu-item-<%# Eval("SubCatId") %>">
                            <a href="index.html">
                                <%# Eval("SubCatName")%></a>
                            <asp:Repeater ID="RptrMyMenuSideSubSub" runat="server" EnableTheming="True">
                                <ItemTemplate>
                                    <ul class="sub-menu">
                                        <asp:Label ID="lblprodid" runat="server" Text='<%# Eval("PRODUCTID") %>' Visible="false"></asp:Label>
                                        <li id="menu-item-<%# Eval("PRODUCTID") %>" class="menu-item-<%# Eval("PRODUCTID") %>">
                                            <a href="index.html">
                                                <%# Eval("PRODUCTNAME")%></a> </li>
                                    </ul>
                                </ItemTemplate>
                            </asp:Repeater>
                        </li>
                    </ul>
                </ItemTemplate>
            </asp:Repeater>
        </li>
    </ItemTemplate>
</asp:Repeater>

 

 

This question does not have replies that have been liked.