ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Bind (Populate) N-Level nested Repeater using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="eshant.kapoor.5">eshant.kapoor</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p>For this example i have used dynamic datatable and folter record using select method to bind the Repeater. You need to replace with database binding code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:Repeater ID=&#34;RptrMyMenuSide&#34; runat=&#34;server&#34; EnableTheming=&#34;True&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;lblcatid&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;CATID&#34;) %&gt;&#39; Visible=&#34;true&#34;&gt;&lt;/asp:Label&gt; &lt;li id=&#34;menu-item-&lt;%# Eval(&#34;CATID&#34;)%&gt;&#34; class=&#34;menu-item-&lt;%# Eval(&#34;CATID&#34;)%&gt;&#34;&gt;&lt;a&gt; &lt;%# Eval(&#34;CATNAME&#34;)%&gt;&lt;/a&gt; &lt;asp:Repeater ID=&#34;RptrMyMenuSideSub&#34; runat=&#34;server&#34; EnableTheming=&#34;True&#34;&gt; &lt;ItemTemplate&gt; &lt;ul class=&#34;sub-menu&#34;&gt; &lt;asp:Label ID=&#34;lblsubcatid&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;SubCatId&#34;) %&gt;&#39; Visible=&#34;true&#34;&gt;&lt;/asp:Label&gt; &lt;li id=&#34;menu-item-&lt;%# Eval(&#34;SubCatId&#34;) %&gt;&#34; class=&#34;menu-item-&lt;%# Eval(&#34;SubCatId&#34;) %&gt;&#34;&gt; &lt;a href=&#34;index.html&#34;&gt; &lt;%# Eval(&#34;SubCatName&#34;)%&gt;&lt;/a&gt; &lt;asp:Repeater ID=&#34;RptrMyMenuSideSubSub&#34; runat=&#34;server&#34; EnableTheming=&#34;True&#34;&gt; &lt;ItemTemplate&gt; &lt;ul class=&#34;sub-menu&#34;&gt; &lt;asp:Label ID=&#34;lblprodid&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;PRODUCTID&#34;) %&gt;&#39; Visible=&#34;false&#34;&gt;&lt;/asp:Label&gt; &lt;li id=&#34;menu-item-&lt;%# Eval(&#34;PRODUCTID&#34;) %&gt;&#34; class=&#34;menu-item-&lt;%# Eval(&#34;PRODUCTID&#34;) %&gt;&#34;&gt; &lt;a href=&#34;index.html&#34;&gt; &lt;%# Eval(&#34;PRODUCTNAME&#34;)%&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; &lt;/li&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { CategoriesSideMenu(); ProductSideMenuSub(); } } public void CategoriesSideMenu() { RptrMyMenuSide.Visible = true; DataTable dt = GetCategory(); RptrMyMenuSide.DataSource = dt; RptrMyMenuSide.DataBind(); } public void ProductSideMenuSub() { for (int i = 0; i &lt;= RptrMyMenuSide.Items.Count - 1; i++) { Label id = (Label)RptrMyMenuSide.Items[i].FindControl(&#34;lblcatid&#34;); Repeater RptrMyMenuSideSub = (Repeater)RptrMyMenuSide.Items[i].FindControl(&#34;RptrMyMenuSideSub&#34;); DataTable dt = GetSubCategoryMaster(); RptrMyMenuSideSub.DataSource = dt.Select(&#34;CategoryId=&#34; + id.Text).CopyToDataTable(); RptrMyMenuSideSub.DataBind(); ProductSideMenuSubSub(RptrMyMenuSideSub); } } public void ProductSideMenuSubSub(Repeater RptrMyMenuSideSub) { for (int i = 0; i &lt;= RptrMyMenuSideSub.Items.Count - 1; i++) { Label id = (Label)RptrMyMenuSideSub.Items[i].FindControl(&#34;lblsubcatid&#34;); Repeater RptrMyMenuSideSubSub = (Repeater)RptrMyMenuSideSub.Items[i].FindControl(&#34;RptrMyMenuSideSubSub&#34;); DataTable dt = GetProduct(); RptrMyMenuSideSubSub.DataSource = dt.Select(&#34;PRODUCTCATID=&#34; + id.Text).CopyToDataTable(); RptrMyMenuSideSubSub.DataBind(); } } private static DataTable GetCategory() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;CATID&#34;, typeof(int)), new DataColumn(&#34;CATNAME&#34;, typeof(string)) }); dt.Rows.Add(1, &#34;Cat 1&#34;); dt.Rows.Add(2, &#34;Cat 2&#34;); dt.Rows.Add(3, &#34;Cat 3&#34;); dt.Rows.Add(4, &#34;Cat 4&#34;); return dt; } private static DataTable GetSubCategoryMaster() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;SubCatId&#34;, typeof(int)), new DataColumn(&#34;SubCatName&#34;, typeof(string)), new DataColumn(&#34;CategoryId&#34;, typeof(int)) }); dt.Rows.Add(1, &#34;Sub Cat 1&#34;, 1); dt.Rows.Add(2, &#34;Sub Cat 2&#34;, 2); dt.Rows.Add(3, &#34;Sub Cat 3&#34;, 4); dt.Rows.Add(4, &#34;Sub Cat 4&#34;, 3); dt.Rows.Add(5, &#34;Sub Cat 5&#34;, 1); return dt; } private static DataTable GetProduct() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;PRODUCTID&#34;, typeof(int)), new DataColumn(&#34;PRODUCTNAME&#34;, typeof(string)), new DataColumn(&#34;PRODUCTCATID&#34;, typeof(string)) }); dt.Rows.Add(1, &#34;Product 1&#34;, 1); dt.Rows.Add(2, &#34;Product 2&#34;, 3); dt.Rows.Add(3, &#34;Product 3&#34;, 5); dt.Rows.Add(4, &#34;Product 4&#34;, 2); dt.Rows.Add(5, &#34;Product 5&#34;, 4); dt.Rows.Add(6, &#34;Product 6&#34;, 4); return dt; }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then CategoriesSideMenu() ProductSideMenuSub() End If End Sub Public Sub CategoriesSideMenu() RptrMyMenuSide.Visible = True Dim dt As DataTable = GetCategory() RptrMyMenuSide.DataSource = dt RptrMyMenuSide.DataBind() End Sub Public Sub ProductSideMenuSub() For i As Integer = 0 To RptrMyMenuSide.Items.Count - 1 Dim id As Label = CType(RptrMyMenuSide.Items(i).FindControl(&#34;lblcatid&#34;), Label) Dim RptrMyMenuSideSub As Repeater = CType(RptrMyMenuSide.Items(i).FindControl(&#34;RptrMyMenuSideSub&#34;), Repeater) Dim dt As DataTable = GetSubCategoryMaster() RptrMyMenuSideSub.DataSource = dt.[Select](&#34;CategoryId=&#34; &amp; id.Text).CopyToDataTable() RptrMyMenuSideSub.DataBind() ProductSideMenuSubSub(RptrMyMenuSideSub) Next End Sub Public Sub ProductSideMenuSubSub(ByVal RptrMyMenuSideSub As Repeater) For i As Integer = 0 To RptrMyMenuSideSub.Items.Count - 1 Dim id As Label = CType(RptrMyMenuSideSub.Items(i).FindControl(&#34;lblsubcatid&#34;), Label) Dim RptrMyMenuSideSubSub As Repeater = CType(RptrMyMenuSideSub.Items(i).FindControl(&#34;RptrMyMenuSideSubSub&#34;), Repeater) Dim dt As DataTable = GetProduct() RptrMyMenuSideSubSub.DataSource = dt.[Select](&#34;PRODUCTCATID=&#34; &amp; id.Text).CopyToDataTable() RptrMyMenuSideSubSub.DataBind() Next End Sub Private Shared Function GetCategory() As DataTable Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() {New DataColumn(&#34;CATID&#34;, GetType(Integer)), New DataColumn(&#34;CATNAME&#34;, GetType(String))}) dt.Rows.Add(1, &#34;Cat 1&#34;) dt.Rows.Add(2, &#34;Cat 2&#34;) dt.Rows.Add(3, &#34;Cat 3&#34;) dt.Rows.Add(4, &#34;Cat 4&#34;) Return dt End Function Private Shared Function GetSubCategoryMaster() As DataTable Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() {New DataColumn(&#34;SubCatId&#34;, GetType(Integer)), New DataColumn(&#34;SubCatName&#34;, GetType(String)), New DataColumn(&#34;CategoryId&#34;, GetType(Integer))}) dt.Rows.Add(1, &#34;Sub Cat 1&#34;, 1) dt.Rows.Add(2, &#34;Sub Cat 2&#34;, 2) dt.Rows.Add(3, &#34;Sub Cat 3&#34;, 4) dt.Rows.Add(4, &#34;Sub Cat 4&#34;, 3) dt.Rows.Add(5, &#34;Sub Cat 5&#34;, 1) Return dt End Function Private Shared Function GetProduct() As DataTable Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() {New DataColumn(&#34;PRODUCTID&#34;, GetType(Integer)), New DataColumn(&#34;PRODUCTNAME&#34;, GetType(String)), New DataColumn(&#34;PRODUCTCATID&#34;, GetType(String))}) dt.Rows.Add(1, &#34;Product 1&#34;, 1) dt.Rows.Add(2, &#34;Product 2&#34;, 3) dt.Rows.Add(3, &#34;Product 3&#34;, 5) dt.Rows.Add(4, &#34;Product 4&#34;, 2) dt.Rows.Add(5, &#34;Product 5&#34;, 4) dt.Rows.Add(6, &#34;Product 6&#34;, 4) Return dt End Function</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/N5kcTpn.jpg" alt="" width="234" height="582" /></p>https://www.aspforums.net:443/Threads/154971/Bind-Populate-N-Level-nested-Repeater-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/154971/Bind-Populate-N-Level-nested-Repeater-using-C-and-VBNet-in-ASPNet/Mon, 26 Aug 2019 05:15:34 GMT