for (int i = 0; i < dlPic.Items.Count; i++)//
{
Image image = (Image)dlPic.Items[i].FindControl("img1");//从datalist的循环中findcontrol到img1
int w=Convert.Toint32(image.Height.Value);//这样转换失败
int h = Convert.ToUInt32(image.Height);//这样转换也失败
if (w > h)
{
image.Style.Add("width","50px");
}
else
{
image.Style.Add("height","50px");
}
}似乎要将Image控件的宽高进行比较很难,试过很多方法都不行,大家有什么好方法吗??
for (int i = 0; i < dlPic.Items.Count; i++)//
{
Image image = (Image)dlPic.Items[i].FindControl("img1");//从datalist的循环中findcontrol到img1
int w = Convert.Toint32(image.Width.ToString().Substring(0, image.Width.ToString().Length - 2));
int h = Convert.ToUInt32(image.Height.ToString().Substring(0, image.Height.ToString().Length - 2));
if (w > h)
{
image.Style.Add("width", "50px");
}
else
{
image.Style.Add("height", "50px");
}
}
http://www.cnblogs.com/insus/articles/1909037.html
http://www.cnblogs.com/insus/articles/2060601.html
http://www.cnblogs.com/insus/articles/2048578.html
function DrawImage(obj,width,height){
var img = new Image();
img.src=obj.src;
if(img.width>width)
obj.width=width;
if(img.height>height)
obj.height=height;
}
</script>