0

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 ?

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
Oshrib
  • 1,789
  • 12
  • 40
  • 67
  • Bad path probably. What is the URL of the image in the browser? Is that the expected URL? Does the image exist at the given URL? – Zabba Sep 08 '11 at 08:04
  • Did any image control get image-value in `foreach` or not? – Rev Sep 08 '11 at 08:04
  • Try to play with Server.MapPath() perhaps it helps – sll Sep 08 '11 at 08:07
  • not, none of the image get. the path is fine - the URL is: theMainRoot(Where the page is)/noImage.jpg – Oshrib Sep 08 '11 at 08:08
  • if the html output is ok, then it's not the Image.ImageUrl fault. Are you sure the image is displayed if you copy paste the url from the html source to the browser url bar ? – remi bourgarel Sep 08 '11 at 08:15

2 Answers2

3

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?

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
0

May be you need to rebind the ListView.

protected void Page_Load(object sender, EventArgs e)
    {
      if(!IsPostBack)
       {
        LV1.DataBind();
        checkTheImage();
       }
    }
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186