0

所以我试图在图像文件夹中添加我保存在我的项目中的图像。但它不起作用

DirectCast(Customer.Items(0).FindControl("imageControl"), Image).ImageUrl = "~/images/IMG_1287.JPG"
DirectCast(Customer.Items(0).FindControl("imageControl"),   Image).DataBind()

客户是图像元素所在的转发器html元素。我不能直接在服务器代码中调用图像元素,因为图像元素位于转发器元素内。所以我必须使用效果很好的 findcontrol 方法。当我调试代码时,我可以确定它找到了正确的图像元素,问题是当我设置 imageurl 时,ui 中似乎没有发生任何事情,但我不明白为什么有人可以帮助我:)

<div>
<asp:Image ID="imageControl" Width="100%" Height="70%" runat="server"/>
</div>
4

1 回答 1

0

在我看来,您似乎没有以正确的方式尝试中继器中的访问控制,它应该是:

如果图像在标题中:

DirectCast(Customer.Controls[0].Controls[0].FindControl("imageControl"), Image).ImageUrl = "~/images/IMG_1287.JPG"

如果图像在页脚中

DirectCast(Customer.Controls[Customer.Controls.Count - 1].Controls[0].FindControl("imageControl"), Image).ImageUrl = "~/images/IMG_1287.JPG"

请查看此帖子以获取更多详细信息。

PS:你用的是vb吗?因为我使用了 C# 语法,如果是的话会相应地改变。

于 2017-08-12T13:36:44.407 回答