Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6608137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:34:40+00:00 2026-05-25T19:34:40+00:00

I need to bind a repeater with hierarchical data as follows: Category1 – Item1

  • 0

I need to bind a repeater with hierarchical data as follows:

Category1
   - Item1
   - Item2
Category2
   - Item3
   - Item4

I currently have a single dataset with the items as well as the category that each item belongs to.

I’m trying to learn Linq and was wondering if there was a way I can do the same using Linq?

Below is what I tried:

var groupbyfilter = from dr in dtListing.AsEnumerable()
                            group dr by dr["Category"];
        DataTable dtFinal = dtListing.Clone();

  foreach (var x in groupbyfilter)
          x.CopyToDataTable(dtFinal, LoadOption.OverwriteChanges);


  rptList.DataSource = dtFinal;
  rptList.DataBind();

But trouble with it is it repeats category for each item.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:34:40+00:00Added an answer on May 25, 2026 at 7:34 pm

    You’ll need a repeater nested inside another.

    Do a distinct on the dtlisting selecting only the category field. Bind this to the outer repeater.

    In the 2nd repeater, select data whose where condition has category field which equals to the value that is being databound to the repeater item. You’d have to handle this in the repeater’s onitem_databound event.

    Here is an example.

    <%@ Import  Namespace="System.Data" %>
          <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
              <ItemTemplate>
                  <div>
                      Category: <b><%# Container.DataItem%></b>
                      <asp:Repeater ID="Repeater2" runat="server">
                          <FooterTemplate>
                              <%="</ul>" %>
                          </FooterTemplate>
                          <HeaderTemplate>
                              <%= "<ul>"%>
                          </HeaderTemplate>
                          <ItemTemplate>
                              <li>
                                  <%# ((Data.DataRow)Container.DataItem)[1] %>, <%#  ((Data.DataRow)Container.DataItem)[0] %>
                              </li>
                          </ItemTemplate>
                      </asp:Repeater>
                  </div>                
              </ItemTemplate>
          </asp:Repeater>
    

    For this sample I used a csv as my datasource, and created a datatable using it. So my codebehind looks like:

    using Microsoft.VisualBasic;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Diagnostics;
    
    public class _Default : System.Web.UI.Page
    {
        DataTable csvData;
        protected void Page_Load(object sender, System.EventArgs e)
        {
            csvData = Utils.csvToDataTable("data.csv", true);
            GridView1.DataSource = csvData;
            GridView1.DataBind();
    
            Repeater1.DataSource =
                (from x in csvData.AsEnumerable() select x["category"]).Distinct();
            Repeater1.DataBind();
        }
    
        protected void Repeater1_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item |
                    e.Item.ItemType == ListItemType.AlternatingItem) {
                Repeater rptr = (Repeater)e.Item.FindControl("Repeater2");
                rptr.DataSource =
                    csvData.AsEnumerable().Where(x => x["category"].Equals(e.Item.DataItem));
                rptr.DataBind();
            }
        }       
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text box and a repeater control. I need to bind the
I need to bind to a Storyboard, but I cant figure how. I have
I have a situation where I need to bind a click event to an
I am using repeater to bind all table data. And My table fields are
I need to bind some data to a DataGrid with variable number of columns.
I need to bind to static properties in my App.xaml.cs class and have so
I need bind some ComboBoxes to one ObservableCollection. I have this ListView . <ListView
It's easy to bind a data source to something like a gridview or repeater,
I have a dropdown on my homepage that I need to bind to a
I had binded DataGrid to my collection, and i need bind height of each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.