binding a nested GridView to field in parent's ObjectDataSource

Posted on 2011-05-02
Medium Priority
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
  • 2

Expert Comment

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

Accepted Solution

RLCornish earned 0 total points
ID: 35506074
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

ID: 35759464
solved own question and posted solution

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

571 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