'Container.DataItem' is not declared

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
 
T

Teemu Keiski

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top