Tech Off Thread

1 post

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Binding GridView to struct properties

Back to Forum: Tech Off
  • User profile image
    Larsenal

    I have an object with several properties that I want to bind to a Grid View.  Binding to simple datatypes such as string, int, and bool work quite well.

    However, one of the properties of my object is a struct.  I would like to be able to bind to properties of the struct.

    For example, if I have an object of type CustomType with the following properties:

    public string Name {
            get { return _name; }
            set { _name = value; }
    }

    public int Age {
            get { return _age; }
            set { _age= value; }
    }

    public CustomStruct Stats {
        get { return _stats;}
        set { _stats = value;}
    }


    where CustomStruct is

        public struct CustomStruct
        {
            private int hours;
            public int Hours
            {
                get { return hours; }
                set { hours= value; }
            }

            private int days;
            public int Days
            {
                get { return days; }
                set { hours= days; }
            }
        }

    So I have these lines under <Columns>

    <asp:BoundField DataField="Age" HeaderText="Age"/>
    <asp:BoundField DataField="Name" HeaderText="Name"/>


    How can I accomplish something equivalent to the following?

    <asp:BoundField DataField="Stats.Days" HeaderText="Days"/>

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.