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 7092805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:21:37+00:00 2026-05-28T08:21:37+00:00

I have one class which contains two more classes like hierarchy. When I’m displaying

  • 0

I have one class which contains two more classes like hierarchy. When I’m displaying in Telerik RadGrid it should display like, when we click on first class row then it should display two rows of related classes as in below figure. Could help me to do this..?

enter image description here

  • 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-28T08:21:38+00:00Added an answer on May 28, 2026 at 8:21 am

    As I answered your previous post, I just took my other answer and modified it to do what you are looking for. The following is the addition of a class that stores hobby info. I then added the needed structure and relations (the different colored squares denote the different classes):

    enter image description here

    Note: The changes here are minimal and the changes are commented as //New something// so they should be easy to see.

    protected void Page_Load(object sender, EventArgs e)
    {
    
    }
    
    protected void RadGrid1_Init(object sender, EventArgs e)
    {
        DefineGridStructure();
    }
    
    private void DefineGridStructure()
    {
        RadGrid1.MasterTableView.DataKeyNames = new string[] { "EmpId" };
    
        RadGrid1.Width = Unit.Percentage(98);
        RadGrid1.PageSize = 5;
        RadGrid1.AllowPaging = true;
        RadGrid1.AllowSorting = true;
        RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
        RadGrid1.AutoGenerateColumns = false;
        RadGrid1.ShowStatusBar = true;
    
        RadGrid1.MasterTableView.PageSize = 5;
    
        //Add columns
        GridBoundColumn boundColumn;
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "EmpId";
        boundColumn.HeaderText = "EmpId";
        RadGrid1.MasterTableView.Columns.Add(boundColumn);
    
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Name";
        boundColumn.HeaderText = "Name";
        RadGrid1.MasterTableView.Columns.Add(boundColumn);
    
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Age";
        boundColumn.HeaderText = "Age";
        RadGrid1.MasterTableView.Columns.Add(boundColumn);
    
        //Detail table - Orders (II in hierarchy level)
        GridTableView tableViewOrders = new GridTableView(RadGrid1);
        tableViewOrders.Width = Unit.Percentage(100);
    
        tableViewOrders.DataKeyNames = new string[] { "EmpId" };
    
        GridRelationFields relationFields = new GridRelationFields();
        relationFields.MasterKeyField = "EmpId";
        relationFields.DetailKeyField = "EmpId";
        tableViewOrders.ParentTableRelation.Add(relationFields);
    
        RadGrid1.MasterTableView.DetailTables.Add(tableViewOrders);
    
        //Add columns
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Street";
        boundColumn.HeaderText = "Street";
        tableViewOrders.Columns.Add(boundColumn);
    
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "City";
        boundColumn.HeaderText = "City";
        tableViewOrders.Columns.Add(boundColumn);
    
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Zip";
        boundColumn.HeaderText = "Zip";
        tableViewOrders.Columns.Add(boundColumn);
    
    
        //New Detail Table #2 - adds in a another class that stores data
    
    
        GridTableView tableViewOrders2 = new GridTableView(RadGrid1);
        tableViewOrders2.Width = Unit.Percentage(100);
    
        tableViewOrders2.DataKeyNames = new string[] { "EmpId" };
    
        GridRelationFields relationFields2 = new GridRelationFields();
        relationFields2.MasterKeyField = "EmpId";
        relationFields2.DetailKeyField = "EmpId";
        tableViewOrders2.ParentTableRelation.Add(relationFields2);
    
        RadGrid1.MasterTableView.DetailTables.Add(tableViewOrders2);
    
        //Add columns
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "HobbyName";
        boundColumn.HeaderText = "HobbyName";
        tableViewOrders2.Columns.Add(boundColumn);
    
    }
    
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        List<Employee> empList = GetEmployeeDetails();
    
        DataSet dataset = new DataSet("DataSet");
    
        System.Data.DataTable dt1 = new System.Data.DataTable();
        dt1.TableName = "Employee";
        dt1.Columns.Add("EmpId");
        dt1.Columns.Add("Name");
        dt1.Columns.Add("Age");
        dataset.Tables.Add(dt1);
    
        System.Data.DataTable dt2 = new System.Data.DataTable();
        dt2.TableName = "Address";
        dt2.Columns.Add("EmpId");
        dt2.Columns.Add("Street");
        dt2.Columns.Add("City");
        dt2.Columns.Add("Zip");
        dataset.Tables.Add(dt2);
    
    
        //New datatable that stores the new classes' data
        DataTable dt3 = new DataTable();
        dt3.TableName = "Hobby";
        dt3.Columns.Add("EmpId");
        dt3.Columns.Add("HobbyName");
        dataset.Tables.Add(dt3);
    
    
        foreach (Employee emp in empList)
        {
            dt1.Rows.Add(new object[] { emp.EmpId, emp.Name, emp.Age });
    
            foreach (Address add in emp.Address)
            {
                dt2.Rows.Add(new object[] { emp.EmpId, add.Street, add.City, add.Zip });
            }
            //New data add loop
            foreach (Hobby hob in emp.Hobby)
            {
                dt3.Rows.Add(new object[] { emp.EmpId, hob.HobbyName });
            }
    
    
        }
    
        RadGrid1.MasterTableView.DataSource = dataset.Tables["Employee"];
        RadGrid1.MasterTableView.DetailTables[0].DataSource = dataset.Tables["Address"];
        //Add the new table to the grid
        RadGrid1.MasterTableView.DetailTables[1].DataSource = dataset.Tables["Hobby"];
    }
    
    private List<Employee> GetEmployeeDetails()
    {
        List<Employee> myEmployees = new List<Employee>();
    
        Employee Steve = new Employee()
        {
            Address = new List<Address>() { new Address { City = "op", Street = "thatstreet", Zip = 23312 } },
            Hobby = new List<Hobby>() { new Hobby() { HobbyName = "Skating" } },
            Age = 23,
            EmpId = "Emp1",
            Name = "SteveIsTheName"
        };
    
    
        Employee Carol = new Employee()
        {
            Address = new List<Address>() {
                        new Address { City = "op2", Street = "thatstreet2", Zip = 23313 },
                        new Address { City = "op3", Street = "thatstreet3", Zip = 23314 }},
            Hobby = new List<Hobby>() { new Hobby() { HobbyName = "Fishing" } },
            Age = 24,
            EmpId = "Emp2",
            Name = "CarolIsTheName"
        };
    
        myEmployees.Add(Steve);
        myEmployees.Add(Carol);
    
        return myEmployees;
    }
    }
    
    class Employee
    {
        public List<Address> Address { get; set; }
    
        public List<Hobby> Hobby { get; set; }
    
        public int Age { get; set; }
    
        public string Name { get; set; }
    
        public string EmpId { get; set; }
    }
    
    class Address
    {
        public string Street { get; set; }
    
        public string City { get; set; }
    
        public int Zip { get; set; }
    }
    
    class Hobby
    {
        public string HobbyName { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datagridview in which one column contains a custom class, which I
I have a base class, B, which has two constructors, one with no paremeters
I have a script which contains two classes. (I'm obviously deleting a lot of
I have an solution in VS 2008 which contains two class library projects and
I have a base windows forms class which contains two buttons: Ok and Cancel.
I have the following code: A disposable class that contains two disposable members. One
I have an IPAddress class which has one property named ip and in its
In one of my applications I have a class which is responsible for user
I have a service class which has overloaded constructors. One constructor has 5 parameters
I have a class Person which can have several Homes, each one with one

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.