[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

OnItemDataBound cannot display image properly in repeater

Posted on 2009-02-17
2
Medium Priority
?
695 Views
Last Modified: 2013-12-17
Hi

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">
<ItemTemplate><tr>
<td><asp:HyperLink ID="lnk" runat="server" ImageUrl=""><asp:Image runat="server" ID="image1" /></asp:HyperLink></td></tr>
</itemTemplate>
 
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();
                }
                else
                {
                    img.Visible = false;
                }
            }
        }

Open in new window

0
Comment
Question by:techques
2 Comments
 
LVL 19

Accepted Solution

by:
daveamour earned 100 total points
ID: 23667858
if (e.Item.ItemType == ListItemType.Item) should be
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 100 total points
ID: 23667863
add this instead of line 8
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

830 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