Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.11/5 (2 votes)
See more:
Hii,

My Image location(url) value is stored in a database.

I need to fetch that url values and by using that values , i should bind my image.
SQL
select Apps_Image_Loc from Apps_Info;

ASP.NET
<asp:Image ID="imgDB" runat="server"  ImageUrl='<%# DataBinder.Eval(Container.DataItem,"Apps_Image_Loc") %>'/>

The above code is not binding the image, help me to fix.
Posted
Updated 30-May-18 2:51am
v2
Comments
Mahmud Hasan 10-Mar-12 16:45pm    
can u share more of ur code?

1 solution

Here is the sample code to bind the image from the folder as:

XML
<asp:DataList ID="dtlist" runat="server" RepeatColumns="4" CellPadding="5">
<ItemTemplate>
<asp:Image Width="100" ID="Image1" ImageUrl='<%# Bind("Name", "~/Images/{0}") %>' runat="server" />

<itemstyle bordercolor="Brown" borderstyle="dotted" borderwidth="3px" horizontalalign="Center">
VerticalAlign="Bottom" />

</itemstyle>


Code behind to load the image as:
C#
protected void BindDataList()
{
 DirectoryInfo dir = new DirectoryInfo(MapPath("Images"));
 FileInfo[] files = dir.GetFiles();
 ArrayList listItems = new ArrayList();
 foreach (FileInfo info in files)
 {
  listItems.Add(info);
 }
 dtlist.DataSource = listItems;
 dtlist.DataBind();
}
 
Share this answer
 

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