Search code examples
c#asp.netlistviewfindcontrol

Image.ImageUrl not working (C#, asp.net)


I have the next code:

<asp:ListView ID="LV1"  runat="server" DataSourceID="LinqDataSource">
<ItemTemplate>     
  <asp:Image ID="Image1" Width="100px" Height="100px" runat="server"  />
   //....and so on till the
</asp:ListView> 

The code behind:

protected void checkTheImage() 
    {
        foreach (ListViewItem item in LV1.Items)
        {
            ((Image)item.FindControl("Image1")).ImageUrl = "~/noImage.jpg";
        }
    } 

And page load:

protected void Page_Load(object sender, EventArgs e)
    {
        checkTheImage();
    }

The problem is - the noImage.jpg is not display... why ?


Solution

  • not sure if your markup is ok, you should also have a closing ItemTemplate tag somewhere... please update your markup.

    just to try out things, does it work if you move the call of checkTheImage(); inside the Page_PreRender?

    is there any place where you DataBind the ListView in your page life cycle?