'Container.DataItem' is not declared

  • Thread starter Thread starter Antony
  • Start date Start date
A

Antony

Hello,

in my aspx.file I have this code inside a datagrid:

<asp:TemplateColumn HeaderText="Picture">
<ItemTemplate>
<asp:Image id="Image1" runat="server" ImageUrl='upload/<%# Container.DataItem("photo")%>'></asp:Image>
</ItemTemplate>
</asp:TemplateColumn>

When I try to execute my page, I dont get any error but the image is not displayed.
Right clicking on web page in Internet Explorer i get this path: "c:\inetpub\wwwroot\website\upload\<%# Container.DataItem("photo")%>"
If i set a breakpoint on asp:image tag, i try to watch Container.DataItem("photo") value but I can read only this message: "'Container.DataItem' is not declared or the module containing it is not loaded in the debugging session."


So, what's wrong?!?

please help
Antony
 
Put it like this in the ItemTemplate

<ItemTemplate>
<asp:Image id="Image1" runat="server" ImageUrl='<%#
DataBinder.Eval(Container.DataItem,"photo","upload/{0}")%>' />
</ItemTemplate>

E.g when binding to a property you need to build it all within the
databinding expression(here with the help of string formatting), otherwise
it all is interpreted as string, and the expression won't be evaluated.
 
Back
Top