Dhaval Ghevariya
Dhaval Ghevariya

Reputation: 77

How to set height of img in c# Code behind?

I am try to set img height which bind in repeater. But i can't :

HtmlImage proImg = item.FindControl("proImg") as HtmlImage;
proImg.Attributes.Add("style", "height:407px;");

can any one give me solution?

Upvotes: 4

Views: 466

Answers (3)

Tummala Krishna Kishore
Tummala Krishna Kishore

Reputation: 8271

This can be done using the ItemDataBound

public void Repeater_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
  if (e.Item.ItemType == ListItemType.Item
    || e.Item.ItemType == ListItemType.AlternatingItem)   
  {
    // I'm assuming you are using HTML img tags 
   HtmlImage proImg = e.Item.FindControl("proImg") as HtmlImage;
      proImg.Attributes.Add("style", "height:407px;");

  }
}

Upvotes: 1

You can directly use height in Image tag like:

<asp:Image Height="407" />

This is the simplest way and it saves lot of processing.

Upvotes: 0

Marius Orha
Marius Orha

Reputation: 670

Try to set:

proImg.Height = 407;

Here you have more details about HtmlImage.Height property: https://msdn.microsoft.com/en-us/en-en/library/office/system.web.ui.htmlcontrols.htmlimage.height(v=vs.71))

Upvotes: 0

Related Questions