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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:28:18+00:00 2026-05-28T03:28:18+00:00

GetEmployeeDetails() method returns the value of type Employee. I need to display that value

  • 0

GetEmployeeDetails() method returns the value of type Employee. I need to display that value in Telerik RadGrid such a way that, when we click on Employee rows it should expands related Address class fields row under the Employee row. Below is the structure of Employee class.

    class Employee
    {
        string EmpId;
        string Name;
        int Age;
        List<Address> address;
    }

    class Address
    {
        string Street;
        string City;
        int Zip;
    }

I have written below code to display Employee details at run time in ASP page using Telerik RadGrid. But its displaying only first level- Employee class fields and Address fields with empty. Could you please help me to come out of this issue…?

    protected void Page_Load(object sender, EventArgs 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);

        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 });
            }
        }

        DataRelation rel = new DataRelation("rel", dataset.Tables["Employee"].Columns["EmpId"], dataset.Tables["Address"].Columns["EmpId"]);
        dataset.Relations.Add(rel);
        RadGrid1.DataSource = dataSet;
        RadGrid1.DataBind();

    }
  • 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-28T03:28:19+00:00Added an answer on May 28, 2026 at 3:28 am

    Per the Telerik site, you must use the “RadGrid1_NeedDataSource” event to do your binding if you wish to have a hierarchy.

    enter image description here

    I got it to work by doing the following. (BTW I used your classes and code so it should be easy to mimic as I will post all the code. You also left out the method GetEmployeeDetails(), so I made my own:

       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 } },
                    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 }},
                    Age = 24,
                    EmpId = "Emp2",
                    Name = "CarolIsTheName"
                };
    
            myEmployees.Add(Steve);
            myEmployees.Add(Carol);
    
            return myEmployees;
        }
    

    Step 1: Define the grid’s hierarchy view:

    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 = 3;
        RadGrid1.AllowPaging = true;
        RadGrid1.AllowSorting = true;
        RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
        RadGrid1.AutoGenerateColumns = false;
        RadGrid1.ShowStatusBar = true;
    
        RadGrid1.MasterTableView.PageSize = 3;
    
        //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);
    }
    

    Step 2: Set your data sources: (No need for DataBind method to be called or relations added, that’s done by the grid)

        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);
    
            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 });
                }
            }
    
            RadGrid1.MasterTableView.DataSource = dataset.Tables["Employee"];
            RadGrid1.MasterTableView.DetailTables[0].DataSource = dataset.Tables["Address"];
    
        }
    

    Step 3: Run it.

    Obviously you may need to make adjustments to your casing as there may be slight capitalization differences. I also adjusted you classes to allow setting of variable data, nothing big:

    class Employee
    {
        public List<Address> Address { 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; }
    }
    

    Hope this helps.

    -JJ

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Oracle function GetEmployeeDetails which saves all the employee details into a
I need to write the following event.I have a Flex datagrid.When I click on
I am trying to execute a namedquery @NamedQuery(name=getEmployeeDetails,query=select e.username,e.email,e.image,e.firstname,e.lastname from Employee e where e.empid=?1)
I have a class, I am using list to get (assigning multiple list entry
So I'm messing around with inhertiance and polymorphism. Everything was going great until I
I'm trying to load data from the jsp response which is a JSON using
So I've been working with inheritance and I've run into a problem. I'm very
Actually i had been practicing some of the java programs today(trying to learn it
I have a simple ExtJs form panel which contains a fileuploadfield. When I submit
I'm very new to C++, I'm trying to get some university work done. I'm

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.