c# - asp.net GridView ImageField set DataImageUrlField result of linq join -


i have gridview built in way:

<asp:gridview runat="server" id="gridview" class="table table-striped table-bordered gvs" autogeneratecolumns="false" onrowdatabound="gridview_rowdatabound">    <columns>                         <asp:imagefield dataimageurlfield="a.profilepicture" headertext="img"></asp:imagefield>                     <asp:boundfield runat="server" headertext="name" datafield="a.name"/>    ... 

i load data gridview in way:

gridview.datasource=getdata(); gridview.databind(); 

the method getdata returns list using linq:

public static list<dynamic> getdata()     {         try         {             using (var context = new entities())             {                 var entities = (from in context.artist                                 join s in context.list_statustype on a.type equals s.code                                 s.table == "artist" && s.field == "type"                                  select new { a, tipo = s.value }).tolist<dynamic>();                 return entities;             }         }         catch (exception ex)         {             console.writeline(ex.message);             return null;         }     } 

when go page, application gives me databind error:

system.web.httpexception: impossible find field or property 'a.profilepicture'


instead, if bound fields in way, works perfectly.

<asp:gridview runat="server" id="gridview" class="table table-striped table-bordered gvs" autogeneratecolumns="false" onrowdatabound="gridview_rowdatabound">    <columns>                         <asp:imagefield dataimageurlfield="immagine" headertext="img"></asp:imagefield>                     <asp:boundfield runat="server" headertext="name" datafield="a.name"/>    ...  public static list<dynamic> getdata()     {         try         {             using (var context = new entities())             {                 var entities = (from in context.artist                                 join s in context.list_statustype on a.type equals s.code                                 s.table == "artist" && s.field == "type"                                  select new { a, immagine=a.profilepicture, tipo = s.value }).tolist<dynamic>();                 return entities;             }         }         catch (exception ex)         {             console.writeline(ex.message);             return null;         }     } 

what problem this? how can fix it?

why not switch templatefield. gives more control. can bind complete list gridview.

<asp:templatefield headertext="img">     <itemtemplate>         <asp:image id="image1" runat="server" imageurl='<%# eval("artist.profilepicture") %>' />     </itemtemplate> </asp:templatefield> 

note eval shows namespace of nested class itself, not name of property in parent class.

and since working list, reccomend switching typed gridview. see answer here: how list data retrieved table in aspx page web form. have access properties in code behind.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -