c# - How to bind list inside list inside grid view? -



c# - How to bind list inside list inside grid view? -

i retrieving info through entity framework. within user table there navigation property of role. within role there property role name. when binding grid , calling binding look using eval getting next error:

databinding: eval("role.rolename") not 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(&quot;role.rolename&quot;)" headertext="user role" />//this causing error </columns> </asp:gridview>

this :

<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:templatefield> <itemtemplate> <asp:gridview id="grid2" runat="server" autogeneratecolumns="false" width="100%"> <columns> <asp:boundfield datafield="rolename" headertext="user role" /> </columns> </asp:gridview> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>

code behind :

protected override void oninit(eventargs e) { gvuserinformation.rowdatabound += gvuserinformation_rowdatabound; } void gvuserinformation_rowdatabound(object sender, gridviewroweventargs e) { var grid2 = (gridview)e.item.findcontrol("grid2"); grid2.datasource = role.where(w => w.rolename = (e.item.dataitem roles).rolename); grid2.bind(); }

c# asp.net linq gridview linq-to-entities

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -