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
298
How to bind to ObjectDataSource Object's Property
posted

Hello,  I was trying to bind to a Model that contains objects as it's property.

Let's say I have a model that looks like

 

public class  Person {

public Name Name {get;set;}

public int Age {get;set;

}

 

public class Name {

public string FirstName {get;set;}

public string LastName {get;set;}

}

 

Now somewhere in my data access code I have method that looks like.

public IList<Person> GetAll(int personId) {

    return new  List<Person> {

 

 new  Person {

                      new Name { FirstName="Vice", LastName="Ganda" },

                       Age = 27 } };

}

 

 

Now, the object datasource is using tthe method above to bind to my WebDataGrid, the markup looks like (Please ignore the TypeName)

   <asp:ObjectDataSource ID="GetPersonsODS" runat="server" 

            SelectMethod="GetAll"  

            TypeName="System.Data.Repositories.PersonRepository">            

            <SelectParameters>

                <asp:QueryStringParameter DefaultValue="0" Name="personId" 

                    QueryStringField="personId" Type="Int32" />

            </SelectParameters>

        </asp:ObjectDataSource>

 

And in my WebDataGrid I would like to access the Name's Properties FirstName and LastName

I want something like this in bound datafield to access the FirstName property of the Name object.

 <ig:BoundDataField DataType="MySystem.Data.Entities.Person" DataFieldName="Name.FirstName" Key="FirstName">

 

                <Header Text="FirstName" />

            </ig:BoundDataField>

 

But this gives me an error like this

Data source field with name 'Person.FirstName cannot be found. Please set the DataFieldName property for the field with 'FirstName' key to correspond to a data field in the data source.

 

I think I'm missing something, please help.


Thank you and best regards,