How to set img height in c # code?

I am trying to set the img height that binds in a repeater. But I can not:

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

can anyone give me a solution?

+4
source share
3 answers

This can be done using 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;");

  }
}
+1
source

Try to install:

proImg.Height = 407;

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

0
source

Image, :

<asp:Image Height="407" />

.

0

Source: https://habr.com/ru/post/1674807/


All Articles