我想在代码隐藏的数据列表中设置图像的宽度和高度。在代码隐藏设置图像宽度/高度 - ASP.NET,C#
计划是根据宽度/高度做一些比这更复杂的事情,因此将aspx文件中的宽度和高度设置为50%不是一种选择。
由于某种原因,我总是得到0的宽度和高度。 Image1.ImageUrl是我所期望的,尽管。有任何想法吗?图像是System.Web.UI.Webcontrols.Image,而不是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);
}