0

so iam trying to add a image i have saved on my project in image folder. But it dosent work

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

customer is the repeater html element the image element is in. I cant call the image element direct in the server code because the image element is inside a repeater element. So i have to use findcontrol method which works good. When i debugg the code i can se that it finds the right image element the problem is when i set the imageurl nothing seems to happen in the ui but i dont understand why can anybody help me please :)

<div>
<asp:Image ID="imageControl" Width="100%" Height="70%" runat="server"/>
</div>
Robel Haile
  • 309
  • 1
  • 5
  • 18

1 Answers1

0

To me it looks like you are not trying access controls within repeater in correct manner , it should be like :

If image is in header :

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

If image is in footer

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

Please have a look at this post for more details.

PS : Are you using vb ? cause i have used C# syntax, if yes change accordingly.

Ankit
  • 5,733
  • 2
  • 22
  • 23