0
我正在通過實體框架檢索數據。在用戶表裏面有一個角色的導航屬性。內部角色有一個屬性角色名稱。但是,它綁定到網格,並呼籲使用eval我收到以下錯誤綁定表達式時:如何綁定網格視圖內列表內部列表?
DataBinding: Eval("Role.RoleName") is not a valid indexed expression.
我的代碼是:
Entities.VSTMEntities vstmEntities = new Entities.VSTMEntities();
var lstUser = (from e in vstmEntities.Users
select e).ToList();
gvUserInformation.DataSource = lstUser;
gvUserInformation.DataBind();
和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>
可能重複http://stackoverflow.com/questions/1130351/gridview-bound-with-with-properties-of-嵌套級) – deostroll