Setting Image Width/Height in codebehind - ASP.NET, C#
<p>I am trying to set the width and height of images in a datalist in the codebehind.  </p>

<p>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.</p>

<p><strong>For some reason I always get 0 for width and height.  Image1.ImageUrl is what i would expect though</strong>.  Any ideas? Image is the System.Web.UI.Webcontrols.Image, not a System.Drawing.Image.</p>

<pre><code>    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);
    }
</code></pre>
