Click here to Skip to main content
15,911,141 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi all,
I am very new to asp.net. I am developing a web application in which I want to show the images on web page related to search query. I have stored image path in db & images on disk.The SQL query for search is also working fine.

To show images on web page,on aspx page I have written following code:

XML
<asp:DataList ID="dataList1" runat="Server" GridLines="Both" Height="105px" HorizontalAlign="Center" RepeatColumns="4" RepeatDirection="Horizontal" RepeatLayout="Table" Width="243px">
<ItemTemplate>
    <img alt="image1" src="<% DataBinder.Eval(Container.DataItem,"path");%>
</ItemTemplate>
<AlternatingItemTemplate>
    <img alt="image1" src="<% DataBinder.Eval(Container.DataItem,"path");%>"
</AlternatingItemTem plate>
</asp:DataList>


where,"path" is the column in a db table.In code behind I am using dataset object & binding it to dalaList1.But I am getting the error "The name 'Container' does not exist in the current context" on the aspx page.

Can anyone help me out please?
Posted
Updated 29-Jul-10 20:48pm
v2

C#
<asp:DataList ID="dataList1" runat="Server" GridLines="Both" Height="105px" HorizontalAlign="Center" RepeatColumns="4" RepeatDirection="Horizontal" RepeatLayout="Table" Width="243px">
    <ItemTemplate>
          <img alt="image1" src='<%# DataBinder.Eval(Container.DataItem,"path") %>'/>
    </ItemTemplate>
    <AlternatingItemTemplate>
          <img alt="image1" src='<%# DataBinder.Eval(Container.DataItem,"path") %>' />
    </AlternatingItemTemplate>
</asp:DataList>
 
Share this answer
 
XML
<asp:DataList ID="dataList1" runat="Server" GridLines="Both" Height="105px" HorizontalAlign="Center" RepeatColumns="4" RepeatDirection="Horizontal" RepeatLayout="Table" Width="243px">
    <ItemTemplate>
          <img alt="image1" src='<%# DataBinder.Eval(Container.DataItem,"path") %>'/>
    </ItemTemplate>
    <AlternatingItemTemplate>
          <img alt="image1" src='<%# DataBinder.Eval(Container.DataItem,"path") %>' />
    </AlternatingItemTemplate>
</asp:DataList>
 
Share this answer
 
Comments
bsaurabh 30-Jul-10 2:50am    
Thanks for the reply.Your suggestions worked
Thank you very much
raju melveetilpurayil 30-Jul-10 2:56am    
you are welcome ;)
If you're 'very new to ASP.NET', this is an insane task for you to undertake. I assume you're in a class, why is your teacher giving you such a complex task ? Or did you know SQL and C# or VB.NET already ?

You use a #, not a %, to specify code that runs in a data context.

[UPDATE]

You missed # in the binding syntax.
Syntax is,
<%# DataBinder.Eval(Container.DataItem, "Path") %>
 
Share this answer
 
v2
Comments
Arun Jacob 30-Jul-10 2:44am    
Both % and #.
:-)
bsaurabh 30-Jul-10 2:51am    
Thanks for the reply.Your suggestion worked.
Reza Nabiloo 25-Mar-13 7:26am    
Thank sooooo much :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900