在中继器控件中显示图像 [英] Show images in Repeater control

查看:114
本文介绍了在中继器控件中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下List:

private List<System.Web.UI.WebControls.Image> _searchResultList = new List<System.Web.UI.WebControls.Image>();

此列表可能包含多个具有不同URL的图像.

This List may contain several Images with different URLs.

我有以下Repeater:

<asp:Panel ID="SearchPanel" runat="server" ScrollBars="Vertical">
    <asp:Repeater ID="Repeater" runat="server">
        <ItemTemplate>
            <asp:Image height="32" width="32" runat="server"/>
        </ItemTemplate>
    </asp:Repeater>
</asp:Panel>

使用DataSource显示图像似乎不起作用.

Using DataSource to display the images doesn't seem to work.

Repeater.DataSource = _searchResultList;           
Repeater.DataBind();

我在做什么错了?

推荐答案

_searchResultList不是字符串列表,因此您不能使用ImageURL='<%Container.DataItem.ToString()%>'.因为_searchResultList是图像列表,所以应绑定ImageUrl属性.这对您来说应该很好:

The _searchResultList is not a list of strings so you can't use ImageURL='<%Container.DataItem.ToString()%>'. Because _searchResultList is a list of images you should bind the ImageUrl property. This should works fine for you:

<asp:Repeater ID="Repeater" runat="server">
    <ItemTemplate> 
       <asp:Image ID="Image1" height="32" width="32" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' /> 
    </ItemTemplate>
</asp:Repeater>

在此示例中,Container.DataItem引用Image控件.这就是为什么我们使用Eval("ImageUrl")来获取每个Image控件的ImageUrl属性的原因.

In this example Container.DataItem refers to an Image control. This is why we used Eval("ImageUrl") to get the ImageUrl property of each Image control.

这篇关于在中继器控件中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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