在asp.net的Repeater Control中绑定图像 [英] Bind an image in Repeater Control of asp.net

查看:76
本文介绍了在asp.net的Repeater Control中绑定图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,



我的图片位置(网址)值存储在数据库中。



我需要获取该url值并使用该值,我应该绑定我的图像。

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.

select Apps_Image_Loc from Apps_Info;




<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.

推荐答案

下面是将图像从文件夹绑定的示例代码:



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

<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:

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();
}


这篇关于在asp.net的Repeater Control中绑定图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆