所以我试图在图像文件夹中添加我保存在我的项目中的图像。但它不起作用
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>