4

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?

Jaqen H'ghar
  • 16,186
  • 8
  • 49
  • 52
  • refer here http://stackoverflow.com/questions/7190413/dynamically-change-an-images-height-using-codebehind – Mark Apr 14 '17 at 07:23
  • What do you mean by `But i can't`? Is there an error? is the height not set? Is the height wrong? Without some more context we're just guessing. – VDWWD Apr 14 '17 at 19:42

3 Answers3

1

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;");

  }
}
Krsna Kishore
  • 8,233
  • 4
  • 32
  • 48
0

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))

Marius Orha
  • 670
  • 1
  • 9
  • 26
0

You can directly use height in Image tag like:

<asp:Image Height="407" />

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