• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

Repeater question

Hi Experts,

How to find the html img tag in the c# and set its url in the rptVehicles_ItemDataBound event of the Repeater?

HTML Code:
<img src='<%# Eval("VendorLogo","~/TAImages/ServiceProviderLogos/{0}")%>' alt="SP" id="imgVendorLogo" />

C# Code:
 RepeaterItem item = e.Item;
        if (item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Label lblVendorName = (Label)e.Item.FindControl("lblVendorName");
            if (lblVendorName.Text == "ZCars")
            {
                Image vendorlogo = (Image)e.Item.FindControl("imgVendorLogo");
                vendorlogo.ImageUrl = "abc.jpg";

            }
        }
Please help!

I am getting issue in the underlined code i.e not able to access the img tag.

please not its not server site image but html side.
0
Dinesh Kumar
Asked:
Dinesh Kumar
1 Solution
 
Rajar AhmedConsultantCommented:
You must have runat server inorder to findcontrol in itemdatabound .

Try this,
<img runat="server" src='<%# Eval("VendorLogo","~/TAImages/ServiceProviderLogos/{0}")%>' alt="SP" id="imgVendorLogo" />

Open in new window

HtmlImage vendorlogo = (HtmlImage)e.Item.FindControl("imgVendorLogo");
vendorlogo.Src = "abc.jpg";

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now