techques
asked on
OnItemDataBound cannot display image properly in repeater
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#.
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;
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.