This is a migrated thread and some comments may be shown as answers.

Binding RadGrid to Object with nested collection?

2 Answers 459 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Software
Top achievements
Rank 1
Software asked on 17 Jan 2012, 11:15 PM
I have a collection of objects that I want to bind to a RadGrid.  Each object has a "AppName" property, as well as a collection of "Flag" objects.  The Flag object has a "FlagName" property.  So a simplified example of the object model would look like this:
public class Application
{
    public string AppName { get; set; }
    public List<Flag> Flags { get; set; }
}
public class Flag
{
    public string FlagName { get; set; }
    public bool IsAssigned { get; set; }
}

A sample object might look like this:
List<Application> apps = new List<Application> {
    new Application { AppName = "Search App",
        Flags = new List<Flag> {
            new Flag { FlagName = "Editor", IsAssigned = true },
            new Flag { FlagName = "User", IsAssigned = false },
            new Flag { FlagName = "Search", IsAssigned = true },
        }
    },
    new Application { AppName = "Probe",
        Flags = new List<Flag> {
            new Flag { FlagName = "Master", IsAssigned = false },
            new Flag { FlagName = "User", IsAssigned = true },
            new Flag { FlagName = "Publisher", IsAssigned = true },
        }
    },
    new Application { AppName = "Viewer App",
        Flags = new List<Flag> {
            new Flag { FlagName = "Editor", IsAssigned = false },
            new Flag { FlagName = "Baker", IsAssigned = true },
            new Flag { FlagName = "Search", IsAssigned = false },
        }
    }
};

(I just typed that out here, so there may be some code errors, but you get the idea)

So I want to use the RadGrid to display the list of all Applications, grouped by AppName, and then show the Flags for each Application below with a CheckboxColumn which will be set based on the IsAssigned bool for the Flag.  Is there an example somewhere that shows how to do this?  I've tried myself, and searched a bit but I can't find any sample code showing how to wire up a collection with a nested collection to a RadGrid. 

As always, your help is appreciated!

Thanks,
Eddie

2 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 20 Jan 2012, 02:26 PM
Hi,

There are two approaches to choose from in this case:

  • First, to use the internal grouping feature of RadGrid. If you choose this option you need to join both datasources in a new one. Then to provide group expression for the MsterTableView object and thus the grid will be grouped and you will get the nested structure.
  • Second approach is to use "real' hierarchy structure. This could be achieved by defining multiple TableView objects and assigning different datasource to each TableView. Finally, you need to specify the TableView relations either by providing a declarative parent/child table relation or using the DetailDataBind event of RadGrid.

Give these suggestions a try and check which is the most convenient to you.


All the best,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Jesse
Top achievements
Rank 1
Veteran
answered on 21 Aug 2013, 10:22 PM
Did you solve this? If so, what was your solution? Thanks.
Tags
Grid
Asked by
Software
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Jesse
Top achievements
Rank 1
Veteran
Share this question
or