Let's have the following SQL Server table (dbo.resource):
The parent_id column points to the parent resource (id column of the same table).
The resource tree can be loaded using the following code:
protected void Page_Load(object sender, EventArgs e) { if (!IsCallback) { loadResources(); } } private void loadResources() { DayPilotScheduler1.Resources.Clear(); foreach (DataRow dr in loadRootResources().Rows) { int id = (int)dr["id"]; string name = (string)dr["name"]; Resource r = new Resource(name, id.ToString()); r.Expanded = true; DayPilotScheduler1.Resources.Add(r); addChildren(r); } } private void addChildren(Resource parent) { foreach (DataRow dr in loadChildResources(parent.Value).Rows) { int id = (int)dr["id"]; string name = (string)dr["name"]; Resource r = new Resource(name, id.ToString()); r.Expanded = true; parent.Children.Add(r); addChildren(r); } } private DataTable loadChildResources(string parentId) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM [resource] WHERE [parent_id] = @parent", ConfigurationManager.ConnectionStrings["daypilot"].ConnectionString); da.SelectCommand.Parameters.AddWithValue("parent", parentId); DataTable dt = new DataTable(); da.Fill(dt); return dt; } private DataTable loadRootResources() { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM [resource] WHERE [parent_id] is null", ConfigurationManager.ConnectionStrings["daypilot"].ConnectionString); DataTable dt = new DataTable(); da.Fill(dt); return dt; }