Search code examples
c#.netasp.netvb.net.net-2.0

How can I display a List(Of Object) which has single objects and child List(Of Object)?


Limited to using v2.0 of .Net framework (we use VB.net) due to environmental constraints on our servers.

I've got an ASP.net webpage which pulls data from a webservice that performs checks on user accounts in active directory. Operators can check multiple accounts at one time using the web interface. The webservice returns a list(of AccountCheck) objects which themselves contain single properties like username, email address, and List(of AccountError) objects which contain multiple properties.

So the account check objects look like this:

Username
FriendlyName
Email
AccountError1 > Message > Weight > ResolverTeam > etc
AccountError2 > Message > Weight > ResolverTeam > etc
AccountError3 > Message > Weight > ResolverTeam > etc
AccountError4 > Message > Weight > ResolverTeam > etc
AccountError5 > Message > Weight > ResolverTeam > etc

Username
FriendlyName
Email
AccountError1 > Message > Weight > ResolverTeam > etc
AccountError2 > Message > Weight > ResolverTeam > etc
AccountError3 > Message > Weight > ResolverTeam > etc
AccountError4 > Message > Weight > ResolverTeam > etc
AccountError5 > Message > Weight > ResolverTeam > etc

Username
FriendlyName
Email
AccountError1 > Message > Weight > ResolverTeam > etc
AccountError2 > Message > Weight > ResolverTeam > etc
AccountError3 > Message > Weight > ResolverTeam > etc
AccountError4 > Message > Weight > ResolverTeam > etc
AccountError5 > Message > Weight > ResolverTeam > etc

etc

What I want to do is using some kind of repeater, create multiple panels or divs which contain labels showing the username, email etc, and a gridview which has the accounterror list bound to it to show all the errors. The users could be checking 2, 5, 7 accounts at once, and is dynamic.

What's the best way to go about this?


Solution

  • You will need to nest two list controls; for example, a repeater and a gridview, or a repeater and a repeater, depending on how much control you need over the layout. The relevant part is to data bind the DataSource of the inner control to the inner list:

    <asp:Repeater ...>
        <ItemTemplate>
            <%# Eval("Username") %>
            ...
            <asp:GridView DataSource='<%# Eval("AccountErrors") %>' ...>
               ...
            </asp:GridView>
        </ItemTemplate>
    </asp:Repeater>