I have this following data source binding:
MembershipProvider provider = new MembershipProvider(); UserUpdateLogs userUpdateLogs = provider.GetUserUpdateLogs(username); dgUserUpdateLog.DataSource = userUpdateLogs.Logs; dgUserUpdateLog.DataBind();
Logs is a collection of UserUpdateLogEntry. This class owns the UserData Property, and UserData contains other properties. My aspx:
<Columns> <asp:BoundColumn DataField='ChangeDate' Visible='true' HeaderText='Date'/> <asp:BoundColumn DataField='UserData.Sex' HeaderText='Sex' /> <asp:BoundColumn DataField='UserData.Phone' HeaderText='Phone' /> </Columns>
The first row (ChangeDate) seems to work well. But when rendering the second BoundColumn, the following error is shown:
A field or property with the name ‘UserData.Sex’ was not found on the selected data source.
Why does it happen? Can’t Aspx recognize a concatenation of properties like PropertyA.PropertyB?
I’ve checked the object and all properties have valid data.
You can not bind to properties of sub-objects in that way.
As an alternative, you can use a template column and use Eval to display the properties of the sub-object, e.g. something like this: