Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
95
Can't bind UltraWebGrid to Hierarchical Business Object (from SubSonic)
posted

We're having an issue with the UltraWebGrid. I have  datasource objects created using SubSonic. Let's say the parent and child are related on the property pA (I exclude all the "get/set" code for purposes of brevity);

Public Class Parent
{
  public int pA;
  public int pB;
  public ChildCollection childColl;
}

Public Class ParentCollection
{
  public List<Parent>;
}

Public Class Child
{
  public int pA;
  public int cA;
  public string childDesc;
}

Public Class ChildCollection
{
   public List<Child>;
}

Let's ignore how the collections are populated for this discussion.

So my Band[0] should have a collection of Parent objects. My Band[1] should have for each Parent an associated collection of Child objects that match the parent on the pA property and can be found by the property Parent.childColl in each Parent object in the ParentCollection.

We can bind Band[0] to the ParentCollection object just fine. There doesn't seem to even be any syntax to bind Band[1] to the childColl property of each object in the ParentCollection. I think we're overlooking something, but what?

Please provide an example of how to do this. This is driving us all crazy!

  • 21382
    posted

     If that is the object definition the WebGrid will not bind to it.  The WebGrid uses public properties to get it's values, so a class structure like this would work:  As you can see I opened up the member variables as properties. 

     

            public class Parent
            {
                public Parent()
                {
                    this.childColl = new ChildCollection();
                }
                public int pA;
                public int pB;
                public ChildCollection childColl;

                public int PA
                {
                    get
                    {
                        return this.pA;
                    }
                }

                public ChildCollection Kids
                {
                    get
                    {
                        return this.childColl;
                    }
                }
            }
            #region collections
            public class ParentCollection : List<Parent>
            {
            }
            public class ChildCollection : List<Child>
            {
            }
            #endregion

            public class Child
            {
                public int pA;
                public int cA;
                public string childDesc;

                public Child(int pa, int cA, string desc)
                {
                    this.pA = pa;
                    this.cA = cA;
                    this.childDesc = desc;
                }

                public int CA
                {
                    get
                    {
                        return this.cA;
                    }
                }
                public string DESC
                {
                    get
                    {
                        return this.childDesc;
                    }
                }
            }


            protected void Page_Load(object sender, EventArgs e)
            {
                ParentCollection pc = new ParentCollection();
                Parent p = new Parent();
                p.pA = 1;
                p.pB = 1;
                pc.Add(p);

                p = new Parent();
                p.pA = 2;
                p.pB = 1;

                Child c = new Child(p.pA, 1, "Child 1");
                p.childColl.Add(c);
                pc.Add(p);

                this.UltraWebGrid1.DataSource = pc;
                this.UltraWebGrid1.DisplayLayout.ViewType = Infragistics.WebUI.UltraWebGrid.ViewType.Hierarchical;
                this.UltraWebGrid1.DataBind();
            }

     

  • 8680
    posted

    I've never bound a collection to a grid, but what seems to be missing is a way for the grid to discern the relationship between the two collections.

    I've done it with a multi-table dataset that included relationship definitions:  http://forums.infragistics.com/forums/p/3298/17902.aspx#17902

    Let us know what you end up doing, OK?