I am trying to set the width and height of images in a datalist in the codebehind.
The plan is to do something more complex than this based on the width/height, so setting width and height in the aspx file to 50% is not an option.
For some reason I always get 0 for width and height. Image1.ImageUrl is what i would expect though. Any ideas? Image is the System.Web.UI.Webcontrols.Image, not a System.Drawing.Image.
protected void DataList9_ItemDataBound(object sender, DataListItemEventArgs e)
{
Image Image1 = (Image)e.Item.FindControl("Image1");
double height = Image1.Height.Value;
double width = Image1.Width.Value;
height = height * 0.5;
width = width * 0.5;
Image1.Height = new Unit(height);
Image1.Width = new Unit(width);
}