Hi, I have a data object arranged in the following manner:
public class Class1{public int Value1 { get; set; }public List<Class2> FirstChildSet { get; set; }}public class Class2{public string Value2 { get; set; }public string Value3 { get; set; }public List<Class3> SecondChildSet { get; set; }}public class Class3{public string Value4 { get; set; }public int Value5 { get; set; }}public class Question{public List<Class1> GetData(){List<Class1> data = new List<Class1>();// Fill data from databasereturn data;}}
I would like to be able to bind a List<Class1> via an ObjectDataSource to a WebHierarchicalDataGrid and see the data laid out like this:
Value1
Value2 Value 3
Value 4 Value 5
Anyone have idea of how to accomplish this? Thanks.
Hello bartsipes,
In this scenario you can use “WebHierarchicalDataSource” control and configure it to use the different objects - http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.2/CLR4.0/html/Web_WebHierarchicalDataSource.html
You should add the needed relations to your Data Source in order to provide correct display of the grid parent and child bands.
http://samples.infragistics.com/aspnet/Samples/WebHierarchicalDataSource/Data/IntegrateDisperseData/Default.aspx?cn=hierarchical-data-source&sid=aee04b5e-aacd-4d41-9bb4-49648cc31d3d
I hope that this approach will be useful in your scenario.
Hey Alex, thanks for the reply. Unfortunately, I was not able to figure out what I need from that sample code. In the sample, the hierarchical data source has two other data sources that it uses to join data together via a DataRelation and then provide to the grid. The data I am trying to display has only one ObjectDataSource that has IEnumerable<T> child collections. I don't see any information on how to setup a DataReleation on an object for IEnumerable collections. According to the documentation (http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.2/CLR4.0/html/WebHierarchicalDataGrid_About_WebHierarchicalDataGrid.html) this is supported: "Hierarchical Data Source Support – Supports all hierarchical data source controls as well as DataSet objects and objects that implement the IEnumerable interface. "
I'm posting below a sample scenario of what I am trying to accomplish.
Here are my supporting classes that layout the object models:
using System;using System.Collections.Generic;using System.Linq;using System.Web;
namespace HierarchicalGrid.App_Code{ public class Class1 { public string Value1 { get; set; } public List<Class2> FirstChildSet { get; set; } } public class Class2 { public string Value2 { get; set; } public string Value3 { get; set; } public List<Class3> SecondChildSet { get; set; } } public class Class3 { public string Value4 { get; set; } public int Value5 { get; set; } } public class DataHelper { public List<Class1> GetData() { List<Class1> data = new List<Class1>() { new Class1() { Value1 = "First Row", FirstChildSet = new List<Class2>() { new Class2() { Value2 = "We got a sub row", Value3 = "moles", SecondChildSet = new List<Class3>() { new Class3() { Value4 = "THRID LEVEL", Value5 = 1, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 2, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 3, }, } }, new Class2() { Value2 = "Second Sub row", Value3 = "antelope", SecondChildSet = new List<Class3>() { new Class3() { Value4 = "THRID LEVEL under second row", Value5 =4, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 5, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 6, }, } }, } }, new Class1() { Value1 = "Second Row", FirstChildSet = new List<Class2>() { new Class2() { Value2 = "We got a sub row", Value3 = "moles", SecondChildSet = new List<Class3>() { new Class3() { Value4 = "THRID LEVEL", Value5 = 7, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 8, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 9, }, } }, new Class2() { Value2 = "Second Sub row", Value3 = "antelope", SecondChildSet = new List<Class3>() { new Class3() { Value4 = "THRID LEVEL under second row", Value5 = 10, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 11, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 12, }, } }, } }, new Class1() { Value1 = "Third Row", FirstChildSet = new List<Class2>() { new Class2() { Value2 = "We got a sub row", Value3 = "moles", SecondChildSet = new List<Class3>() { new Class3() { Value4 = "THRID LEVEL", Value5 = 13, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 14, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 15, }, } }, new Class2() { Value2 = "Second Sub row", Value3 = "antelope", SecondChildSet = new List<Class3>() { new Class3() { Value4 = "THRID LEVEL under second row", Value5 = 16, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 17, }, new Class3() { Value4 = "THRID LEVEL", Value5 = 18, }, } }, } }, };
return data; } }}
And here is my test web page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HierarchicalGrid.Default" %>
<%@ Register Assembly="Infragistics4.Web.v11.2, Version=11.2.20112.1019, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.Web.UI.DataSourceControls" TagPrefix="ig" %><%@ Register Assembly="Infragistics4.Web.v11.2, Version=11.2.20112.1019, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="sm" runat="server" /> <ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" Height="350px" AutoGenerateBands="True" AutoGenerateColumns="True" Width="400px" DataMember="ObjectDataSource1_DefaultView" DataSourceID="WebHierarchicalDataSource1" Key="ObjectDataSource1_DefaultView"> </ig:WebHierarchicalDataGrid> <ig:WebHierarchicalDataSource ID="WebHierarchicalDataSource1" runat="server"> <DataViews> <ig:DataView ID="ObjectDataSource1_DefaultView" DataMember="DefaultView" DataSourceID="ObjectDataSource1" /> </DataViews> </ig:WebHierarchicalDataSource> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="HierarchicalGrid.App_Code.DataHelper" DataObjectTypeName="HierarchicalGrid.App_Code.Class1"> </asp:ObjectDataSource> </form></body></html>