I am retrieving data through entity framework. Inside User Table there is a navigation property of role. Inside role there is a property role name. But when binding it to grid and calling the binding expression using Eval i am getting the following error:
DataBinding: Eval("Role.RoleName") is not a valid indexed expression.
My code is:
Entities.VSTMEntities vstmEntities = new Entities.VSTMEntities();
var lstUser = (from e in vstmEntities.Users
select e).ToList();
gvUserInformation.DataSource = lstUser;
gvUserInformation.DataBind();
and aspx:
<asp:GridView ID="gvUserInformation" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Username" HeaderText="UserName" />
<asp:BoundField DataField="Password" HeaderText="Password" />
<asp:BoundField DataField="Email" HeaderText="Email Address" />
<asp:BoundField DataField="User_Status" HeaderText="User Status" />
<asp:BoundField DataField="Eval("Role.RoleName")" HeaderText="User Role" />//This causing error
</Columns>
</asp:GridView>