binding a nested GridView to field in parent's ObjectDataSource

Posted on 2011-05-02
Last Modified: 2013-11-05
I have an ASP.NET 4.0 WebForm with a parent/child “nested” GridView – child GridView is the third column of the parent GridView.

My goal is to fetch all the data in one shot – parent and child.  To facilitate that, I chose the following format (chose it over XML, which seemed more problematic?)

Item business object (has ID, Value and IsValueRequired properties

Group  business object (has ID and IList<Item> properties) - a container of Items
IList<Group> groups => bind to ParentGridView (using ObjectDataSource, dsGroups)

So, I have the “child” IList available in dsGroups. Just can’t figure out how to bind the IList property to ChildGridView (3rd column) and which event is most appropriate  - OnRowDataBound of parent?

Suggestions?   Would this be any easier using hierarchical XML?  My web research seems to suggest that Objects are easier for a GridView to bind to.

Question by:RLCornish
    LVL 6

    Expert Comment

    I think you have it figured out pretty good with the OnRowDataBound of the parent!

    Accepted Solution

    Figured it out.  Posting solution code for others with same issue.  (Code and names have been simplified for example purposes) - Group and Item are placeholder names for "business objects"

        protected void ParentGridView_RowDataBound(object sender, GridViewRowEventArgs e)
          if (e.Row.RowType == DataControlRowType.DataRow)
            GridView gvChild = e.Row.FindControl("GridViewChild") as GridView;
            if (gvChild!= null)
              if (e.Row.DataItem is Group)
                Group grp = (Group)e.Row.DataItem;
                gvChild.DataSource = grp.Items;    // IList<Item>

    Author Closing Comment

    solved own question and posted solution

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now