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,
Sherwin,
Were you able to find a solution to this problem?
Any solution available for this post, like subclass field as key field .
Hi,
As u mentioned setting the value in the initialize row , the sorting is not working for the subproperty objects.
Any other work around available.
Thanks,
If you are trying to sort on the initial load, you may need to bind once to set the values in the unbound cells in initialize row and then bind AGAIN to have it sort on the unbound field.
-Dave
Can u pls modify the sample uploaded above and work sorting.
Any Updates Infra Team.
Hello Raja,
I am attaching the modified sample. If you have any questions, please let me know.