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控件的宽高进行比较很难,试过很多方法都不行,大家有什么好方法吗??

解决方案 »

  1.   


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

  2.   

    Reset image:
    http://www.cnblogs.com/insus/articles/1909037.html
    http://www.cnblogs.com/insus/articles/2060601.html
      

  3.   

    漏了这个:
    http://www.cnblogs.com/insus/articles/2048578.html
      

  4.   

    <img src="images/1.jpg" onload="DrawImage(this,50,50)" />    <script type="text/javascript">
            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>