OnItemDataBound cannot display image properly in repeater

Posted on 2009-02-17
Last Modified: 2013-12-17

I need to display an image in a repeater if the product status is 1.
I have 10 rows of records. Only the 10th record product status is 0.
The following code display images only in 1,3,5,7,9 records.
2,4,6,8 records show images not available with 'X' in a square.
And, 10th image also shows image not available but it should be invisible.

What's wrong with it?

I use VC#.
<ASP:REPEATER id="repeaterItems" runat="server" OnItemDataBound="ItemDataBound">


<td><asp:HyperLink ID="lnk" runat="server" ImageUrl=""><asp:Image runat="server" ID="image1" /></asp:HyperLink></td></tr>


protected void ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)


            if (e.Item.ItemType == ListItemType.Item)


                HyperLink lnk = (HyperLink)e.Item.FindControl("lnk");

                System.Data.DataRowView dv = (System.Data.DataRowView)e.Item.DataItem;

                Image img = (Image)e.Item.FindControl("image1");

                img.ImageUrl = "images/product.gif";

                if (dv.Row["status"].ToString() == "1")


                    img.Visible = true;

                    lnk.NavigateUrl = "product.aspx?id=" + dv.Row["productid"].ToString();




                    img.Visible = false;




Open in new window

Question by:techques
    LVL 19

    Accepted Solution

    if (e.Item.ItemType == ListItemType.Item) should be
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
    LVL 26

    Assisted Solution

    by:Anurag Thakur
    add this instead of line 8
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now