I need to display list of lists in a hierarchical way.
This code shows it flat.
How to do?
using System;using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication25 { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { List<Item> ls = new List<Item>(); Item it = new Item(); it.x = 1; it.y = 2; ls.Add(it); Item it1 = new Item(); it1.x = 4; it1.y = 5; ls.Add(it1); Item it2 = new Item(); it2.x = 9; it2.y = 10; List<Item> ls1 = new List<Item>(); ls1.Add(it2); Item it3 = new Item(); it3.x = 13; it3.y = 14; List<Item> ls2 = new List<Item>(); ls2.Add(it3); List<List<Item>> lsLs = new List<List<Item>>(); lsLs.Add(ls); lsLs.Add(ls1); lsLs.Add(ls2); WebHierarchicalDataGrid1.DataSource = lsLs; WebHierarchicalDataGrid1.DataBind(); } } public class Item { public int x { get; set; } public int y { get; set; } } }
Hello drpoalim,
Thanks for sharing your solution with the community.
I've wrapped the list of items, with a class, and added a primary key, and than it worked.
Hi drpoalim,
I'm just checking if you have any questions regarding the matter.
This behavior is expected, because the List is not a hierarchical structure. There are no parent/child relations, that's why it is displayed as flat table.
Let me know if you have any further questions.