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>
Thanks for the suggestion but I was finally able to figure out how to accomplish what I wanted from some of the other forum postings. Its actually quite easy to do. Just get rid of the WebHierarchicalDataSource and set the datasource of the WebHierarchicalDataGrid on page load to a object on page load. Works perfectly.
It would be very nice if you guys would give a sample showing how to take advantage of the IEnumerable support of the WebHierarchicalDataGrid.
Below is my sample code:
<%@ 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" Width="400px" DataKeyFields="Value1"> <Bands> <ig:Band DataKeyFields="Value2" DataMember="FirstChildSet" AutoGenerateColumns="false"> <Bands> <ig:Band DataKeyFields="Value4" DataMember="SecondChildSet" AutoGenerateColumns="false"> <Columns> <ig:BoundDataField DataFieldName="Value4" Key="Value4"> <Header Text="Value4" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Value5" Key="Value5" DataType="System.Int32"> <Header Text="Value5" /> </ig:BoundDataField> </Columns> </ig:Band> </Bands> <Columns> <ig:BoundDataField DataFieldName="Value2" Key="Value2"> <Header Text="Value2" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Value3" Key="Value3"> <Header Text="Value3" /> </ig:BoundDataField> </Columns> </ig:Band> </Bands> <Columns> <ig:BoundDataField DataFieldName="Value1" Key="Value1"> <Header Text="Value1" /> </ig:BoundDataField> </Columns> </ig:WebHierarchicalDataGrid> </form></body></html>
using System;using System.Collections.Generic;
namespace HierarchicalGrid{ public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { this.WebHierarchicalDataGrid1.DataSource = DataHelper.GetData(); this.WebHierarchicalDataGrid1.DataBind(); } }
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 static 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, }, } }, } }, };
I will recommend you a different that your approach. You can test it and let me know if it works. Implement GetData methods for each of your classes. Create three DataViews in the HierarchicalDataSource and assigne to them threeObjectDataSources where each of them has a GetData method of any class for “SelectMethod”. Set the relation between the DataViews.
I hope this helps.
Let me know if you have further questions.
Sincerely,
Georgi Sashev
Developer Support Engineer
Infragistics, Inc.
http://es.infragistics.com/support
If it helps, I am trying to migrate from the UltraWebGrid control where I have this scenario already working to the WebHierarchicalDataGrid. I'm just strugging trying figure out how to setup the WebHierarchicalDataGrid so that it knows to create sub rows for the IEnumerable child collections so the user sees a grid that has a total of three bands in it. Thanks.